﻿using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using MaterialDesignThemes.Wpf;
using Newtonsoft.Json;
using System.ComponentModel;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using 充电桩上位机.Model.FTRegisters;
using 充电桩上位机.Model.ModbusRegisters.NetWork;
using 充电桩上位机.Model.ModbusRegisters.User;
using 充电桩上位机.Model.PTAConfig;
using 充电桩上位机.Model.ServerRegisters;
using 充电桩上位机.View.Authorize;
using 充电桩上位机.View.CommonRegistersManagement;
using 充电桩上位机.View.FTRegister;
using 充电桩上位机.View.NetWorkRegisiter;
using 充电桩上位机.View.SerialPortConnection;
using 充电桩上位机.View.ServerRegisters;
using 充电桩上位机.View.UserRegisters;
using 充电桩上位机.ViewModel.FTRegisters;
using 充电桩上位机.ViewModel.NetWorkRegister;
using 充电桩上位机.ViewModel.SerialPortConnection;
using 充电桩上位机.ViewModel.ServerRegisters;
using 充电桩上位机.ViewModel.UserRegisters;
using System.IO;
using 充电桩上位机.Model.Authorize;
using System.Resources;
using System.Globalization;
using System.Reflection;
using 充电桩上位机.Model.PEM;

namespace 充电桩上位机.ViewModel;

public class MainWindowViewModel : ObservableObject
{
    [Category("上位机界面标题")]
    private string _workTitle = string.Empty;
    public string WorkTitle
    {
        get => _workTitle;
        set => SetProperty(ref _workTitle, value);
    }
    [Category("放大界面框")]
    public ICommand MagnifyCommand =>
    new RelayCommand(async () => await MagnifyCommandFunc());
    [Category("缩小界面框")]
    public ICommand ReduceCommand =>
    new RelayCommand(async () => await ReduceCommandFunc());
    [Category("删除界面框")]
    public ICommand DeleteCommand =>
    new RelayCommand(async () => await DeleteCommandFunc());

    [Category("用户设置按钮状态")]

    private bool _userSetStatus = false;
    public bool UserSetStatus
    {
        get => _userSetStatus;
        set => SetProperty(ref _userSetStatus, value);
    }
    [Category("界面切入用户设置")]
    public ICommand UserRegistersCommand =>
    new RelayCommand(async () => await UserRegistersCommandFunc());

    [Category("网络设置按钮状态")]

    private bool _netWorkSetStatus = false;
    public bool NetWorkSetStatus
    {
        get => _netWorkSetStatus;
        set => SetProperty(ref _netWorkSetStatus, value);
    }
    [Category("界面切入网络设置")]
    public ICommand NetworkRegisterCommand =>
    new RelayCommand(async () => await NetworkRegisterCommandFunc());
    [Category("服务寄存器按钮状态")]

    private bool _serverRegistersSetStatus = false;
    public bool ServerRegistersSetStatus
    {
        get => _serverRegistersSetStatus;
        set => SetProperty(ref _serverRegistersSetStatus, value);
    }
    [Category("界面切入网络设置")]
    public ICommand ServerRegistersCommand =>
        new RelayCommand(async () => await ServerRegistersCommandFunc());

    [Category("硬件寄存器按钮状态")]

    private bool _fTRegistersSetStatus = false;
    public bool FTRegistersSetStatus
    {
        get => _fTRegistersSetStatus;
        set => SetProperty(ref _fTRegistersSetStatus, value);
    }
    [Category("界面切入硬件设置")]
    public ICommand FTRegistersCommand =>
        new RelayCommand(async () => await FTRegistersCommandFunc());

    [Category("界面配置刷新按钮")]
    public ICommand RefreshConfigCommand =>
        new RelayCommand(async () => await RefreshConfigCommandFunc());
    [Category("界面配置写入按钮")]
    public ICommand SetConfigCommand =>
        new RelayCommand(async () => await SetConfigCommandFunc());

    #region 界面层
    [Category("网络连接寄存器界面")]
    private static  ContentControl _userNeedShowControl = new();
    public ContentControl UserNeedShowControl
    {
        get => _userNeedShowControl;
        set => SetProperty(ref _userNeedShowControl, value);
    }
    [Category("串口通信界面")]
    private ContentControl _serialPortConnectionUserControl = new();
    public ContentControl SerialPortConnectionUserControl
    {
        get => _serialPortConnectionUserControl;
        set => SetProperty(ref _serialPortConnectionUserControl, value);
    }
    [Category("公共测试集界面")]
    private ContentControl _commonRegistersManagementUserControl = new();
    public ContentControl CommonRegistersManagementUserControl
    {
        get => _commonRegistersManagementUserControl;
        set => SetProperty(ref _commonRegistersManagementUserControl, value);
    }
    #endregion

    public ICommand LockCommand =>
    new RelayCommand(async () => await LockCommandCommandFunc());
    public Task LockCommandCommandFunc()
    {
        Authorize authorize = new Authorize();
        authorize.ShowDialog();
        return Task.CompletedTask;
    }
    #region 逻辑层
    [Category("界面放大逻辑")]
    private async Task MagnifyCommandFunc()
    {
        //normal 变更
        var window = Application.Current.MainWindow;
        window.WindowState = window.WindowState == WindowState.Maximized ?
            WindowState.Normal : WindowState.Maximized;
        await Task.Delay(2);
    }
    [Category("界面缩小逻辑")]
    private async Task ReduceCommandFunc()
    {
        var window = Application.Current.MainWindow;
        window.WindowState = WindowState.Minimized;
        await Task.Delay(2);
    }
    [Category("界面关闭逻辑")]
    private async Task DeleteCommandFunc()
    {
        //加判断框，暂时先放着
        await Task.Delay(2);
        Environment.Exit(0);
    }

    [Category("用户寄存器设置界面逻辑")]
    private Task UserRegistersCommandFunc()
    {
        Application.Current.Dispatcher.InvokeAsync(delegate
        {
            UserNeedShowControl = new UserRegistersView();
            NetWorkSetStatus = false;
            FTRegistersSetStatus = false;
            ServerRegistersSetStatus = false;
            UserSetStatus = true;
            WorkTitle = User_Regisiter;
        });
        return Task.CompletedTask;
    }

    [Category("网络寄存器设置界面逻辑")]
    private Task NetworkRegisterCommandFunc()
    {
        Application.Current.Dispatcher.InvokeAsync(delegate
        {
            UserNeedShowControl = new NetworkRegisiterView();
            UserSetStatus = false;
            ServerRegistersSetStatus = false;
            FTRegistersSetStatus = false;
            NetWorkSetStatus = true;
            WorkTitle = Network_Regisiter;
        });
        return Task.CompletedTask;
    }
    [Category("服务寄存器设置界面逻辑")]
    private Task ServerRegistersCommandFunc()
    {
        Application.Current.Dispatcher.InvokeAsync(delegate
        {
            UserNeedShowControl = new ServerRegistersView();
            UserSetStatus = false;
            NetWorkSetStatus = false;
            FTRegistersSetStatus = false;
            ServerRegistersSetStatus = true;

            WorkTitle = Server_Regisiter;
        });
        return Task.CompletedTask;
    }
    [Category("硬件寄存器设置界面逻辑")]
    private Task FTRegistersCommandFunc()
    {

        Application.Current.Dispatcher.InvokeAsync(delegate
        {
            UserNeedShowControl = new FTRegistersView();
            UserSetStatus = false;
            NetWorkSetStatus = false;
            ServerRegistersSetStatus = false;
            FTRegistersSetStatus = true;

            WorkTitle = FT_Regisiter;
        });
        return Task.CompletedTask;
    }
    private Visibility _fTVisibility = Visibility.Hidden;
    public Visibility FTVisibility
    {
        get => _fTVisibility;
        set => SetProperty(ref _fTVisibility, value);
    }
    #region 进度条相关
    [Category("进度条进度")]
    private static double ProcessData { get; set; } = 0;
    private string _processText = string.Empty;
    public string ProcessText
    {
        get => _processText;
        set => SetProperty(ref _processText, value);
    }

    private string _nowLanguage = string.Empty;
    public string NowLanguage
    {
        get => _nowLanguage;
        set => SetProperty(ref _nowLanguage, value);
    }
    #region 选择语言
    private bool _englishCheck = false;
    public bool EnglishCheck
    {
        get => _englishCheck;
        set {
            Application.Current.Dispatcher?.InvokeAsync(delegate {
                if (value)
                {
                    globellanguage = "en-US";
                    NowLanguage = "English";
                    ChineseCheck = false;
                    GlobleLanguageChangeFunc();
                    if (UserSetStatus)
                        UserNeedShowControl = new UserRegistersView();
                    else if (NetWorkSetStatus)
                        UserNeedShowControl = new NetworkRegisiterView();
                    else if (ServerRegistersSetStatus)
                        UserNeedShowControl = new ServerRegistersView();
                    else if (FTRegistersSetStatus)
                        UserNeedShowControl = new FTRegistersView();
                }
            });
            SetProperty(ref _englishCheck, value); 
        }
    }
    private string _englishImage = string.Empty;
    public string EnglishImage
    {
        get => _englishImage;
        set => SetProperty(ref _englishImage, value);
    }    
    private bool _chineseCheck = false;
    public bool ChineseCheck
    {
        get => _chineseCheck;
        set {
            Application.Current.Dispatcher?.InvokeAsync(delegate {
                if (value)
                {
                    globellanguage = "zh-CN";
                    NowLanguage = "简体中文";
                    EnglishCheck = false;
                    GlobleLanguageChangeFunc();
                    if (UserSetStatus)
                        UserNeedShowControl = new UserRegistersView();
                    else if (NetWorkSetStatus)
                        UserNeedShowControl = new NetworkRegisiterView();
                    else if (ServerRegistersSetStatus)
                        UserNeedShowControl = new ServerRegistersView();
                    else if (FTRegistersSetStatus)
                        UserNeedShowControl = new FTRegistersView();

                }
            });
            SetProperty(ref _chineseCheck, value); 
        }
    }
    private string _chinaImage = string.Empty;
    public string ChinaImage
    {
        get => _chinaImage;
        set => SetProperty(ref _chinaImage, value);
    }
    #endregion

    [Category("进度条界面显示")]

    private Visibility _processTaskIsVisibility = Visibility.Hidden;
    public Visibility ProcessTaskIsVisibility
    {
        get => _processTaskIsVisibility;
        set => SetProperty(ref _processTaskIsVisibility, value);
    }
    [Category("主界面显示")]
    private Visibility _processTaskVisibility = Visibility.Visible;
    public Visibility ProcessTaskVisibility
    {
        get => _processTaskVisibility;
        set => SetProperty(ref _processTaskVisibility, value);
    }
    public SnackbarMessageQueue BoundMessageQueue { get; } = new SnackbarMessageQueue();
    public static bool _processIsWork = true;
    private async Task ProcessRun()
    {
        DateTime onlyfans = DateTime.Now;
        while (true)
        {
            await Application.Current.Dispatcher.BeginInvoke(() =>
            {
                if (!_processIsWork)
                {
                    if (ProcessData == 0)
                    {
                        ProcessTaskIsVisibility = Visibility.Visible;
                        ProcessTaskVisibility = Visibility.Hidden;
                        if ((DateTime.Now - onlyfans).TotalSeconds > 5 && ProcessData == 0)
                        {
                            var uiMessageBox = new Wpf.Ui.Controls.MessageBox
                            {
                                Title = "Time out Error",
                                Content = "Please Check The Serial Port.",
                            };
                            var result = uiMessageBox.ShowDialogAsync();
                            ProcessData = 1;
                            return;
                        }
                    }
                    else if (ProcessData == 1)
                    {
                        ProcessTaskIsVisibility = Visibility.Hidden;
                        ProcessTaskVisibility = Visibility.Visible;
                        _processIsWork = true;
                        //var uiMessageBox = new Wpf.Ui.Controls.MessageBox
                        //{
                        //    Title = "Reg Message.",
                        //    Content =
                        //            "Read OK. ",
                        //};
                        //var result = await uiMessageBox.ShowDialogAsync();
                        ProcessData = 0;
                    }
                }
                else
                {
                    onlyfans = DateTime.Now;
                }
                ProcessText = (ProcessData * 100.0).ToString("f2") + "%";
            });
            await Task.Delay(100);
        }
    }
    public static Task ChangeTheProcess(int changedata, int basicdata)
    {
        ProcessData = ((double)changedata / (double)basicdata);
        return Task.CompletedTask;
    }
    public static Task TakeStartOrEnd(bool state)
    {
        _processIsWork = state;
        return Task.CompletedTask;
    }
    #endregion
    public static byte theslaveaddr = 0x01;
    private async Task RefreshConfigCommandFunc()
    {
        if (!SerialPortConnectionViewModel._joinCommand)
        {
            var uiMessageBox = new Wpf.Ui.Controls.MessageBox
            {
                Title = "Error",
                Content = "Please Open Serial Port First.",
            };
            var result = uiMessageBox.ShowDialogAsync();
            return;
        }
        await ChangeTheProcess(0, 1);
        await TakeStartOrEnd(false);
        await Task.Delay(100);
        if (UserSetStatus)
        {
            var ct = (_userNeedShowControl as UserRegistersView);
            var regsview = (ct!.DataContext as UserRegistersViewModel);
            //到该目录下进行填充
            var _ = await SerialPortConnectionViewModel.iAQBHController.AQReadData(theslaveaddr,
                (ushort)mB_UserRegisiters.用户密码地址, mB_UserRegisiters.直接按键停止充电使能地址 - mB_UserRegisiters.用户密码地址 + 1);
            // Convert the modified byte array to a string using ASCII encoding
            pTAConfigModel.用户密码 = UShortToString(_, mB_UserRegisiters.用户密码地址 - mB_UserRegisiters.用户密码地址, 5, 10, false);
            pTAConfigModel.Modbus = _[mB_UserRegisiters.Modbus地址 - mB_UserRegisiters.用户密码地址].ToString();
            pTAConfigModel!.RS485波特率 = _[mB_UserRegisiters.RS485波特率地址 - mB_UserRegisiters.用户密码地址];
            pTAConfigModel!.Mac充电是否启动 = _[mB_UserRegisiters.Mac充电是否启动地址 - mB_UserRegisiters.用户密码地址] == 1 ? true : false;
            pTAConfigModel!.POS是否启动 = _[mB_UserRegisiters.POS是否启动地址 - mB_UserRegisiters.用户密码地址] == 1 ? true : false;
            pTAConfigModel!.DC枪兼容充电模式是否启用 = _[mB_UserRegisiters.DC枪兼容充电模式是否启用地址 - mB_UserRegisiters.用户密码地址] == 1 ? true : false;
            pTAConfigModel!.AC枪兼容充电模式是否启用 = _[mB_UserRegisiters.AC枪兼容充电模式是否启用地址 - mB_UserRegisiters.用户密码地址] == 1 ? true : false;

            //拿取精度
            pTAConfigModel!.POS金额单位 = UShortToString(_, mB_UserRegisiters.POS金额单位地址 - mB_UserRegisiters.用户密码地址, 2, 4, false);
            var jdlist = await SerialPortConnectionViewModel.iAQBHController.AQReadData(theslaveaddr,
                (ushort)mB_UserRegisiters.货币单位精度, 1);
            pTAConfigModel!.货币单位精度 = jdlist[mB_UserRegisiters.货币单位精度 - mB_UserRegisiters.货币单位精度].ToString();

            pTAConfigModel!.POS预扣款金额 = Math.Round((((_[
                mB_UserRegisiters.POS预扣款金额地址 - mB_UserRegisiters.用户密码地址] << 16) |
                _[mB_UserRegisiters.POS预扣款金额地址 - mB_UserRegisiters.用户密码地址 + 1]) / 1000.0), jdlist[0]).ToString();

            pTAConfigModel!.单位电价每kwh的价格 = Math.Round((((_[mB_UserRegisiters.单位电价每kwh的价格地址 - mB_UserRegisiters.用户密码地址] << 16) |
                _[mB_UserRegisiters.单位电价每kwh的价格地址 - mB_UserRegisiters.用户密码地址 + 1]) / Math.Pow(10, jdlist[0])), jdlist[0]).ToString();

            pTAConfigModel!.单位小时服务费 = Math.Round((((_[mB_UserRegisiters.单位小时服务费地址 - mB_UserRegisiters.用户密码地址] << 16) |
                _[mB_UserRegisiters.单位小时服务费地址 - mB_UserRegisiters.用户密码地址 + 1]) / Math.Pow(10, jdlist[0])), jdlist[0]).ToString();
            pTAConfigModel!.遥测数据设置 = _[mB_UserRegisiters.遥测数据设置地址 - mB_UserRegisiters.用户密码地址] == 1 ? true : false;
            pTAConfigModel!.LCD第一语言 = _[mB_UserRegisiters.LCD第一语言地址 - mB_UserRegisiters.用户密码地址];
            pTAConfigModel!.LCD第二语言 = _[mB_UserRegisiters.LCD第二语言地址 - mB_UserRegisiters.用户密码地址] == 255 ? regsview!.Languages.Count() - 1 : _[mB_UserRegisiters.LCD第二语言地址 - mB_UserRegisiters.用户密码地址];
            //Enable_the_Second_Platform
            pTAConfigModel!.是否启用自动使用MAC充电 = _[mB_UserRegisiters.是否启用自动使用MAC充电地址 - mB_UserRegisiters.用户密码地址] == 1 ? true : false;
            pTAConfigModel!.屏幕右下角的文字 = UShortToString(_, mB_UserRegisiters.屏幕右下角的文字地址 - mB_UserRegisiters.用户密码地址, 10, 20, false);

            pTAConfigModel!.MAC上报格式 = _[mB_UserRegisiters.MAC上报格式地址 - mB_UserRegisiters.用户密码地址];
            pTAConfigModel!.RFID是否禁用 = _[mB_UserRegisiters.RFID是否禁用地址 - mB_UserRegisiters.用户密码地址] == 1 ? true : false;
            pTAConfigModel!.是否锁定使用UTC时间 = _[mB_UserRegisiters.是否锁定使用UTC时间地址 - mB_UserRegisiters.用户密码地址] == 1 ? true : false;
            pTAConfigModel!.直接按键停止充电使能 = _[mB_UserRegisiters.直接按键停止充电使能地址 - mB_UserRegisiters.用户密码地址] == 1 ? true : false;
            //OCPP 纯前端操作， 打开则开启 0E7存储寄存器
            await ChangeTheProcess((int)mB_UserRegisiters.直接按键停止充电使能地址, (int)mB_UserRegisiters.服务费单位地址);

            var ocpp1 = await SerialPortConnectionViewModel.iAQBHController.AQReadData(theslaveaddr,
                (ushort)mB_UserRegisiters.OCPP遥测服务器URL_CPID地址, 64);
            var ocpp2 = await SerialPortConnectionViewModel.iAQBHController.AQReadData(theslaveaddr,
                (ushort)mB_UserRegisiters.OCPP遥测服务器URL_CPID地址 + 64, 64);

            pTAConfigModel!.OCPP遥测服务器URL_CPID =
                UShortToString(ocpp1, 0, 64, 128, false) +
            UShortToString(ocpp2, 0, 64, 128, false);

            await ChangeTheProcess((int)mB_UserRegisiters.OCPP遥测服务器HTTP身份校验使能地址, (int)mB_UserRegisiters.服务费单位地址);
            _ = await SerialPortConnectionViewModel.iAQBHController.AQReadData(theslaveaddr,
                (ushort)mB_UserRegisiters.OCPP遥测服务器HTTP身份校验使能地址, mB_UserRegisiters.服务费单位地址 - mB_UserRegisiters.OCPP遥测服务器HTTP身份校验使能地址 + 1);

            pTAConfigModel!.OCPP遥测服务器HTTP身份校验使能 = _[mB_UserRegisiters.OCPP遥测服务器HTTP身份校验使能地址 - mB_UserRegisiters.OCPP遥测服务器HTTP身份校验使能地址] == 1 ? true : false;

            pTAConfigModel!.OCPP遥测服务器HTTP身份校验用户名 = UShortToString(_, mB_UserRegisiters.OCPP遥测服务器HTTP身份校验用户名地址 - mB_UserRegisiters.OCPP遥测服务器HTTP身份校验使能地址, 13, 25, true);
            pTAConfigModel!.OCPP遥测服务器HTTP身份校验密码 = UShortToString(_, mB_UserRegisiters.OCPP遥测服务器HTTP身份校验密码地址 - mB_UserRegisiters.OCPP遥测服务器HTTP身份校验使能地址, 13, 25, true);

            pTAConfigModel!.是否禁止未插枪远程鉴权 = _[mB_UserRegisiters.是否禁止未插枪远程鉴权地址 - mB_UserRegisiters.OCPP遥测服务器HTTP身份校验使能地址] == 1 ? true : false;
            pTAConfigModel!.离线IC卡允许在OCPP模式下进行本地缓存校验 = _[mB_UserRegisiters.离线IC卡允许在OCPP模式下进行本地缓存校验地址 - mB_UserRegisiters.OCPP遥测服务器HTTP身份校验使能地址] == 1 ? true : false;
            pTAConfigModel!.PE检测是否禁用 = _[mB_UserRegisiters.PE检测是否禁用地址 - mB_UserRegisiters.OCPP遥测服务器HTTP身份校验使能地址] == 1 ? true : false;
            pTAConfigModel!.时间 = $"{_[mB_UserRegisiters.时间地址
                - mB_UserRegisiters.OCPP遥测服务器HTTP身份校验使能地址 + 2]}/{_[mB_UserRegisiters.时间地址
                - mB_UserRegisiters.OCPP遥测服务器HTTP身份校验使能地址 + 1]}/{(2000 + _[mB_UserRegisiters.时间地址
                - mB_UserRegisiters.OCPP遥测服务器HTTP身份校验使能地址])} {(_[mB_UserRegisiters.时间地址
                - mB_UserRegisiters.OCPP遥测服务器HTTP身份校验使能地址 + 3])}:{(_[mB_UserRegisiters.时间地址
                - mB_UserRegisiters.OCPP遥测服务器HTTP身份校验使能地址 + 4])}:{(_[mB_UserRegisiters.时间地址
                - mB_UserRegisiters.OCPP遥测服务器HTTP身份校验使能地址 + 5])}";

            pTAConfigModel!.离线IC卡号1 = UShortToString(_, mB_UserRegisiters.离线IC卡号1地址 - mB_UserRegisiters.OCPP遥测服务器HTTP身份校验使能地址, 10, 20, false);
            pTAConfigModel!.离线IC卡号2 = UShortToString(_, mB_UserRegisiters.离线IC卡号2地址 - mB_UserRegisiters.OCPP遥测服务器HTTP身份校验使能地址, 10, 20, false);
            pTAConfigModel!.离线IC卡号3 = UShortToString(_, mB_UserRegisiters.离线IC卡号3地址 - mB_UserRegisiters.OCPP遥测服务器HTTP身份校验使能地址, 10, 20, false);
            pTAConfigModel!.离线IC卡号4 = UShortToString(_, mB_UserRegisiters.离线IC卡号4地址 - mB_UserRegisiters.OCPP遥测服务器HTTP身份校验使能地址, 10, 20, false);
            pTAConfigModel!.离线IC卡号5 = UShortToString(_, mB_UserRegisiters.离线IC卡号5地址 - mB_UserRegisiters.OCPP遥测服务器HTTP身份校验使能地址, 10, 20, false);

            pTAConfigModel!.禁用服务器时间来校准充电桩 = _[mB_UserRegisiters.禁用服务器时间来校准充电桩地址 - mB_UserRegisiters.OCPP遥测服务器HTTP身份校验使能地址] == 1 ? true : false;
            pTAConfigModel!.Bootnotification在每次重新连接服务器后都会重新发送一次 = _[mB_UserRegisiters.Bootnotification在每次重新连接服务器后都会重新发送一次地址 - mB_UserRegisiters.OCPP遥测服务器HTTP身份校验使能地址] == 1 ? true : false;
            pTAConfigModel!.Heart总是根据配置项定时发送_不受Websocket的ping_pong影响 = _[mB_UserRegisiters.Heart总是根据配置项定时发送_不受Websocket的ping_pong影响地址 - mB_UserRegisiters.OCPP遥测服务器HTTP身份校验使能地址] == 1 ? true : false;

            pTAConfigModel!.是否启用Modbus临时功率限制 = _[mB_UserRegisiters.是否启用Modbus临时功率限制地址 - mB_UserRegisiters.OCPP遥测服务器HTTP身份校验使能地址];
            pTAConfigModel!.是否启用离线充电模式下即插即用 = _[mB_UserRegisiters.是否启用离线充电模式下即插即用地址 - mB_UserRegisiters.OCPP遥测服务器HTTP身份校验使能地址] == 1 ? true : false;
            pTAConfigModel!.是否启用OCPP延迟连接 = _[mB_UserRegisiters.是否启用OCPP延迟连接地址 - mB_UserRegisiters.OCPP遥测服务器HTTP身份校验使能地址] == 1 ? true : false;
            pTAConfigModel!.POS机启动的数据不经过OCPP平台_当POS机启动充电的时候_枪头会变为unavaliable = _[mB_UserRegisiters.POS机启动的数据不经过OCPP平台_当POS机启动充电的时候_枪头会变为unavaliable地址 - mB_UserRegisiters.OCPP遥测服务器HTTP身份校验使能地址] == 1 ? true : false;
            pTAConfigModel!.地锁支持 = _[mB_UserRegisiters.地锁支持地址 - mB_UserRegisiters.OCPP遥测服务器HTTP身份校验使能地址] == 1 ? true : false;
            pTAConfigModel!.自动使用MAC充电倒计时秒数 = _[mB_UserRegisiters.自动使用MAC充电倒计时秒数地址 - mB_UserRegisiters.OCPP遥测服务器HTTP身份校验使能地址].ToString();
            pTAConfigModel!.服务费单位 = _[mB_UserRegisiters.服务费单位地址 - mB_UserRegisiters.OCPP遥测服务器HTTP身份校验使能地址];


            _ = await SerialPortConnectionViewModel.iAQBHController.AQReadData(theslaveaddr,
                (ushort)mB_UserRegisiters.LCD视频广告播放策略, mB_UserRegisiters.充电启动失败后是否自动恢复到Available或Preparing状态 - mB_UserRegisiters.LCD视频广告播放策略 + 1);

            pTAConfigModel.LCD视频广告播放策略 = _[mB_UserRegisiters.LCD视频广告播放策略 - mB_UserRegisiters.LCD视频广告播放策略];
            pTAConfigModel.LCD视频广告存放位置 = _[mB_UserRegisiters.LCD视频广告存放位置 - mB_UserRegisiters.LCD视频广告播放策略];
            pTAConfigModel.LCD视频广告存放数量 = _[mB_UserRegisiters.LCD视频广告存放数量 - mB_UserRegisiters.LCD视频广告播放策略].ToString();
            pTAConfigModel.充电桩启动充电过程异常_是上报suspend还是上报_fault = _[mB_UserRegisiters.充电桩启动充电过程异常_是上报suspend还是上报_fault - mB_UserRegisiters.LCD视频广告播放策略];
            pTAConfigModel.是否允许充电桩未插枪本地刷卡_无按钮_插枪界面允许直接刷卡鉴权 = _[mB_UserRegisiters.是否允许充电桩未插枪本地刷卡_无按钮_插枪界面允许直接刷卡鉴权 - mB_UserRegisiters.LCD视频广告播放策略] == 1 ? true : false;
            pTAConfigModel.OfflineMeterValue_禁用 = _[mB_UserRegisiters.OfflineMeterValue_禁用 - mB_UserRegisiters.LCD视频广告播放策略] == 1 ? true : false;
            pTAConfigModel.每次断网重连后_StatusNotification_发送逻辑设定 = _[mB_UserRegisiters.每次断网重连后_StatusNotification_发送逻辑设定 - mB_UserRegisiters.LCD视频广告播放策略];

            pTAConfigModel!.充电启动失败后是否自动恢复到Available或Preparing状态
                 = _[mB_UserRegisiters.充电启动失败后是否自动恢复到Available或Preparing状态 -
                 mB_UserRegisiters.LCD视频广告播放策略];

            #region 中间量转换
            regsview!.UserPassword = pTAConfigModel.用户密码;
            regsview!.ModbusAddress = pTAConfigModel.Modbus;
            regsview!.RS485Baud = pTAConfigModel.RS485波特率! ?? 0;
            regsview!.MacCharging = pTAConfigModel.Mac充电是否启动! ?? false;
            regsview!.PosCharing = pTAConfigModel.POS是否启动! ?? false;
            regsview!.DC_Complatible_Charging = pTAConfigModel.DC枪兼容充电模式是否启用 ?? false;
            regsview!.AC_Complatible_Charging = pTAConfigModel.AC枪兼容充电模式是否启用 ?? false;

            regsview!.PosAmountUnit = pTAConfigModel.POS金额单位;
            regsview!.Currency_Unit_Precision = pTAConfigModel.货币单位精度;
            regsview!.PosWithholdingAmount = pTAConfigModel.POS预扣款金额;
            regsview!.ElecPrice = pTAConfigModel.单位电价每kwh的价格;
            regsview!.ServiceCharge = pTAConfigModel.单位小时服务费;
            regsview!.Enable_the_Second_Platform = pTAConfigModel.遥测数据设置 ?? false;
            regsview!.LDCLangurageFirst = pTAConfigModel.LCD第一语言 ?? 12;
            regsview!.LDCLangurageSecond = pTAConfigModel.LCD第二语言 ?? 12;
            regsview!.AutomaticChargingforMac = pTAConfigModel.是否启用自动使用MAC充电 ?? false;
            regsview!.ShowScreen = pTAConfigModel.屏幕右下角的文字;
            regsview!.MacReportFormat = pTAConfigModel.MAC上报格式 ?? 0;
            regsview!.Disabled_RFID = pTAConfigModel.RFID是否禁用 ?? false;
            regsview!.LockToUseUtcTime = pTAConfigModel.是否锁定使用UTC时间 ?? false;
            regsview!.PressButtonToStopCharging = pTAConfigModel.直接按键停止充电使能 ?? false;
            regsview!.OCPPCheckData = pTAConfigModel.OCPP遥测服务器URL_CPID;

            regsview!.OCPPUserInit = pTAConfigModel.OCPP遥测服务器HTTP身份校验使能 ?? false;
            regsview!.OCPPUserName = pTAConfigModel.OCPP遥测服务器HTTP身份校验用户名;
            regsview!.OCPPUserPassword = pTAConfigModel.OCPP遥测服务器HTTP身份校验密码;
            regsview!.ForbidAuthorizeInUnplug = pTAConfigModel.是否禁止未插枪远程鉴权 ?? false;
            regsview!.Offline_IC_CardLocal_Authorization = pTAConfigModel.离线IC卡允许在OCPP模式下进行本地缓存校验 ?? false;
            regsview!.DisablePE = pTAConfigModel.PE检测是否禁用 ?? false;
            regsview!.EquipTime = pTAConfigModel.时间;
            regsview!.Offline_Card_1 = pTAConfigModel.离线IC卡号1;
            regsview!.Offline_Card_2 = pTAConfigModel.离线IC卡号2;
            regsview!.Offline_Card_3 = pTAConfigModel.离线IC卡号3;
            regsview!.Offline_Card_4 = pTAConfigModel.离线IC卡号4;
            regsview!.Offline_Card_5 = pTAConfigModel.离线IC卡号5;
            regsview!.Calibrating_EVSE_Using_ServerTime = pTAConfigModel.禁用服务器时间来校准充电桩 ?? false;
            regsview!.Retransmit_Notifications_on_Reconnect = pTAConfigModel.Bootnotification在每次重新连接服务器后都会重新发送一次 ?? false;
            regsview!.Scheduled_Heartbeat_Sending = pTAConfigModel.Heart总是根据配置项定时发送_不受Websocket的ping_pong影响 ?? false;
            regsview!.ModbusLimit = pTAConfigModel.是否启用Modbus临时功率限制 ?? 0;
            regsview!.Enable_plug = pTAConfigModel.是否启用离线充电模式下即插即用 ?? false;
            regsview!.Delayed_Connection = pTAConfigModel.是否启用OCPP延迟连接 ?? false;
            regsview!.No_Pass_OCPP = pTAConfigModel.POS机启动的数据不经过OCPP平台_当POS机启动充电的时候_枪头会变为unavaliable ?? false;
            regsview!.Ground_Lock_Support = pTAConfigModel.地锁支持 ?? false;
            regsview!.Automatic_MAC_Charging_Countdown_in_Seconds = pTAConfigModel.自动使用MAC充电倒计时秒数;
            regsview!.ServiceFeeUnit = pTAConfigModel.服务费单位 ?? 0;

            regsview!.SelLCDOpenLogical = pTAConfigModel.LCD视频广告播放策略 ?? 0;
            regsview!.SelLCDOpenAddr = pTAConfigModel.LCD视频广告存放位置 ?? 0;
            regsview!.SelLCDOpenAccount = pTAConfigModel.LCD视频广告存放数量;
            regsview!.SelErrorStartElecMsg = pTAConfigModel.充电桩启动充电过程异常_是上报suspend还是上报_fault ?? 0;
            regsview!.No_Pass_Clash = pTAConfigModel.是否允许充电桩未插枪本地刷卡_无按钮_插枪界面允许直接刷卡鉴权.Value;
            regsview!.OfflineMaterValue = pTAConfigModel.OfflineMeterValue_禁用.Value;
            regsview!.SelRestartLine = pTAConfigModel.每次断网重连后_StatusNotification_发送逻辑设定 ?? 0;
            regsview!.SelCharging_Start_Failure = pTAConfigModel.充电启动失败后是否自动恢复到Available或Preparing状态 ?? 0;

            #region 超垃圾的代码，尽量别改
            if (pTAConfigModel!.OCPP遥测服务器URL_CPID == "ws://47.97.181.104:8080/steve/websocket/CentralSystemService/(chargeBoxId)")
                regsview!.Steve_1 = true;
            else if (pTAConfigModel!.OCPP遥测服务器URL_CPID == "ws://47.101.173.122:8080/steve/websocket/CentralSystemService/(chargeBoxId)")
                regsview!.Steve_2 = true;
            else if (pTAConfigModel!.OCPP遥测服务器URL_CPID == "wss://www.evocpp.com/ocpp/evid")
                regsview!.EVSaas = true;
            else if (pTAConfigModel!.OCPP遥测服务器URL_CPID == "wss://zbox.evocpp.com/ocpp/evid")
                regsview!.Z_BOX = true;
            else if (!string.IsNullOrEmpty(pTAConfigModel!.OCPP遥测服务器URL_CPID))
                regsview!.OtherIsCheck = true;
            #endregion

            #endregion
            await ChangeTheProcess((int)mB_UserRegisiters.OCPP遥测服务器HTTP身份校验使能地址, (int)mB_UserRegisiters.OCPP遥测服务器HTTP身份校验使能地址);
        }
        else if (NetWorkSetStatus)
        {
            var ct = (_userNeedShowControl as NetworkRegisiterView);
            var regsview = (ct!.DataContext as NetWorkRegisterViewModel);
            var _ = await SerialPortConnectionViewModel.iAQBHController.AQReadData(theslaveaddr,
                (ushort)mB_NetWorkRegisiters.离线模式使能地址, 102);

            pTAConfigModel!.离线模式使能 = _[mB_NetWorkRegisiters.离线模式使能地址 - mB_NetWorkRegisiters.离线模式使能地址] == 1 ? true : false;
            pTAConfigModel!.自动切换网络 = _[mB_NetWorkRegisiters.自动切换网络地址 - mB_NetWorkRegisiters.离线模式使能地址] == 1 ? true : false;
            pTAConfigModel!.以太网启用 = _[mB_NetWorkRegisiters.以太网启用地址 - mB_NetWorkRegisiters.离线模式使能地址] == 1 ? true : false;
            pTAConfigModel!.WIFI启用 = _[mB_NetWorkRegisiters.WIFI启用地址 - mB_NetWorkRegisiters.离线模式使能地址] == 1 ? true : false;
            pTAConfigModel!.LTE启用 = _[mB_NetWorkRegisiters.LTE启用地址 - mB_NetWorkRegisiters.离线模式使能地址] == 1 ? true : false;

            pTAConfigModel!.WIFI_SSID = UShortToString(_, (mB_NetWorkRegisiters.WIFI_SSID地址 - mB_NetWorkRegisiters.离线模式使能地址), 8, 15, true);
            pTAConfigModel!.WIFI密码 = UShortToString(_, (mB_NetWorkRegisiters.WIFI密码地址 - mB_NetWorkRegisiters.离线模式使能地址), 8, 15, true);
            pTAConfigModel!.APN = UShortToString(_, (mB_NetWorkRegisiters.APN地址 - mB_NetWorkRegisiters.离线模式使能地址), 8, 15, true);
            pTAConfigModel!.APN_User = UShortToString(_, (mB_NetWorkRegisiters.APN_User地址 - mB_NetWorkRegisiters.离线模式使能地址), 8, 15, true);
            pTAConfigModel!.APN_Password = UShortToString(_, (mB_NetWorkRegisiters.APN_Password地址 - mB_NetWorkRegisiters.离线模式使能地址), 8, 15, true);
            pTAConfigModel!.静态IP使能 = _[mB_NetWorkRegisiters.静态IP使能地址 - mB_NetWorkRegisiters.离线模式使能地址] == 1 ? true : false;
            pTAConfigModel!.静态IP = $"{_[mB_NetWorkRegisiters.静态IP地址 - mB_NetWorkRegisiters.离线模式使能地址]}." +
                $"{_[mB_NetWorkRegisiters.静态IP地址 - mB_NetWorkRegisiters.离线模式使能地址 + 1]}." +
                $"{_[mB_NetWorkRegisiters.静态IP地址 - mB_NetWorkRegisiters.离线模式使能地址 + 2]}." +
                $"{_[mB_NetWorkRegisiters.静态IP地址 - mB_NetWorkRegisiters.离线模式使能地址+ 3]}";
            pTAConfigModel!.默认网关 = $"{_[mB_NetWorkRegisiters.默认网关地址 - mB_NetWorkRegisiters.离线模式使能地址]}." +
                $"{_[mB_NetWorkRegisiters.默认网关地址 - mB_NetWorkRegisiters.离线模式使能地址 + 1]}." +
                $"{_[mB_NetWorkRegisiters.默认网关地址 - mB_NetWorkRegisiters.离线模式使能地址 + 2]}." +
                $"{_[mB_NetWorkRegisiters.默认网关地址 - mB_NetWorkRegisiters.离线模式使能地址 + 3]}";
            pTAConfigModel!.子网掩码 = $"{_[mB_NetWorkRegisiters.子网掩码地址 - mB_NetWorkRegisiters.离线模式使能地址]}." +
                $"{_[mB_NetWorkRegisiters.子网掩码地址 - mB_NetWorkRegisiters.离线模式使能地址 + 1]}." +
                $"{_[mB_NetWorkRegisiters.子网掩码地址 - mB_NetWorkRegisiters.离线模式使能地址 + 2]}." +
                $"{_[mB_NetWorkRegisiters.子网掩码地址 - mB_NetWorkRegisiters.离线模式使能地址 + 3]}";

            pTAConfigModel!.自定义DNS = _[mB_NetWorkRegisiters.自定义DNS使能 - mB_NetWorkRegisiters.离线模式使能地址] == 1 ? true : false;
            pTAConfigModel!.自定义首选DNS = $"{_[mB_NetWorkRegisiters.自定义首选DNS - mB_NetWorkRegisiters.离线模式使能地址]}." +
                $"{_[mB_NetWorkRegisiters.自定义首选DNS - mB_NetWorkRegisiters.离线模式使能地址 + 1]}." +
                $"{_[mB_NetWorkRegisiters.自定义首选DNS - mB_NetWorkRegisiters.离线模式使能地址 + 2]}." +
                $"{_[mB_NetWorkRegisiters.自定义首选DNS - mB_NetWorkRegisiters.离线模式使能地址 + 3]}";
            pTAConfigModel!.自定义备用DNS = $"{_[mB_NetWorkRegisiters.自定义备用DNS - mB_NetWorkRegisiters.离线模式使能地址]}." +
                $"{_[mB_NetWorkRegisiters.自定义备用DNS - mB_NetWorkRegisiters.离线模式使能地址 + 1]}." +
                $"{_[mB_NetWorkRegisiters.自定义备用DNS - mB_NetWorkRegisiters.离线模式使能地址 + 2]}." +
                $"{_[mB_NetWorkRegisiters.自定义备用DNS - mB_NetWorkRegisiters.离线模式使能地址 + 3]}";

            regsview!.OfflineChecked = pTAConfigModel!.离线模式使能 ?? false;
            regsview!.AutomaticChecked = pTAConfigModel!.自动切换网络 ?? false;
            regsview!.EtherNetChecked = pTAConfigModel!.以太网启用 ?? false;
            regsview!.WIFIChecked = pTAConfigModel!.WIFI启用 ?? false;
            regsview!.FourGChecked = pTAConfigModel!.LTE启用 ?? false;
            regsview!.WifiSSID = pTAConfigModel!.WIFI_SSID;
            regsview!.WifiPassword = pTAConfigModel!.WIFI密码;
            regsview!.APNAddress = pTAConfigModel!.APN;
            regsview!.APNUserName = pTAConfigModel!.APN_User;
            regsview!.APNPassword = pTAConfigModel!.APN_Password;
            regsview!.EnableEtherNetIPState = pTAConfigModel!.静态IP使能 ?? false;
            regsview!.IPAddress = pTAConfigModel!.静态IP;
            regsview!.IPMask = pTAConfigModel!.默认网关;
            regsview!.DefaultGetWay = pTAConfigModel!.子网掩码;
            regsview!.AutoDNSInit = pTAConfigModel!.自定义DNS ?? false;
            regsview!.DNSFirst = pTAConfigModel!.自定义首选DNS;
            regsview!.DNSSecond = pTAConfigModel!.自定义备用DNS;

            await ChangeTheProcess((int)mB_NetWorkRegisiters.自定义备用DNS, (int)mB_NetWorkRegisiters.自定义备用DNS);
        }
        else if (ServerRegistersSetStatus)
        {
            var ct = (_userNeedShowControl as ServerRegistersView);
            var regsview = (ct!.DataContext as ServerRegistersViewModel);
            var ocpp1 = await SerialPortConnectionViewModel.iAQBHController.AQReadData(theslaveaddr,
                (ushort)mB_ServerRegisiters.OCPP服务器URL, 64);   //64 * 2
            var ocpp2 = await SerialPortConnectionViewModel.iAQBHController.AQReadData(theslaveaddr,
                (ushort)mB_ServerRegisiters.OCPP服务器URL + 64, 64);   //64 * 2
            pTAConfigModel!.OCPP服务器URL = UShortToString(ocpp1, mB_ServerRegisiters.OCPP服务器URL - mB_ServerRegisiters.OCPP服务器URL, 64, 128, false) +
                UShortToString(ocpp2, mB_ServerRegisiters.OCPP服务器URL - mB_ServerRegisiters.OCPP服务器URL, 32, 64, false);
            await ChangeTheProcess((int)mB_ServerRegisiters.OCPP服务器URL, (int)(mB_ServerRegisiters.服务器CA证书文件名 + 1500));

            var _ = await SerialPortConnectionViewModel.iAQBHController.AQReadData(theslaveaddr,
                (ushort)mB_ServerRegisiters.HTTP身份校验使能, 86);   //64 * 2
            pTAConfigModel!.HTTP身份校验使能 = _[mB_ServerRegisiters.HTTP身份校验使能 - mB_ServerRegisiters.HTTP身份校验使能] == 1 ? true : false;
            pTAConfigModel!.HTTP身份校验用户名 = UShortToString(_, mB_ServerRegisiters.HTTP身份校验用户名 - mB_ServerRegisiters.HTTP身份校验使能, 13, 25, true);
            pTAConfigModel!.HTTP身份校验密码 = UShortToString(_, mB_ServerRegisiters.HTTP身份校验密码 - mB_ServerRegisiters.HTTP身份校验使能, 13, 25, true);
            pTAConfigModel!.ChargePointModel_OCPP = UShortToString(_, mB_ServerRegisiters.ChargePointModel_OCPP - mB_ServerRegisiters.HTTP身份校验使能, 25, 50, true);
            pTAConfigModel!.ChargePointVendor = UShortToString(_, mB_ServerRegisiters.ChargePointVendor - mB_ServerRegisiters.HTTP身份校验使能, 10, 20, true);
            var qcode = await SerialPortConnectionViewModel.iAQBHController.AQReadData(theslaveaddr,
                (ushort)mB_ServerRegisiters.QR_Code_1, 50);
            pTAConfigModel!.QR_Code_1 = UShortToString(qcode, mB_ServerRegisiters.QR_Code_1 - mB_ServerRegisiters.QR_Code_1, 50, 100, true);

            var qcode2 = await SerialPortConnectionViewModel.iAQBHController.AQReadData(theslaveaddr,
                (ushort)mB_ServerRegisiters.QR_Code_2, 50);
            pTAConfigModel!.QR_Code_2 = UShortToString(qcode2, mB_ServerRegisiters.QR_Code_2 - mB_ServerRegisiters.QR_Code_2, 50, 100, true);
            var qcode3 = await SerialPortConnectionViewModel.iAQBHController.AQReadData(theslaveaddr,
                (ushort)mB_ServerRegisiters.QR_Code_3, 50);
            pTAConfigModel!.QR_Code_3 = UShortToString(qcode3, mB_ServerRegisiters.QR_Code_3 - mB_ServerRegisiters.QR_Code_3, 50, 100, true);
            var addr = await SerialPortConnectionViewModel.iAQBHController.AQReadData(theslaveaddr,
                (ushort)mB_ServerRegisiters.服务器CA证书文件名, 50);
            pTAConfigModel!.服务器CA证书文件名 = UShortToString(addr, mB_ServerRegisiters.服务器CA证书文件名 - mB_ServerRegisiters.服务器CA证书文件名, 50, 100, true);


            await ChangeTheProcess((int)mB_ServerRegisiters.服务器CA证书文件名, (int)mB_ServerRegisiters.服务器CA证书文件名);

            regsview!.OCPPServer = pTAConfigModel!.OCPP服务器URL;
            regsview!.HTTPChecked = pTAConfigModel!.HTTP身份校验使能 ?? false;
            regsview!.HttpUserName = pTAConfigModel!.HTTP身份校验用户名;
            regsview!.HttpUserPassword = pTAConfigModel!.HTTP身份校验密码;
            regsview!.ChangePointModel = pTAConfigModel!.ChargePointModel_OCPP;
            regsview!.ChargePointVendor = pTAConfigModel!.ChargePointVendor;
            regsview!.QR_Code_1 = pTAConfigModel!.QR_Code_1;
            regsview!.QR_Code_2 = pTAConfigModel!.QR_Code_2;
            regsview!.QR_Code_3 = pTAConfigModel!.QR_Code_3;
            regsview!.AddressText = pTAConfigModel!.服务器CA证书文件名;

            if (pTAConfigModel!.OCPP服务器URL == "ws://47.97.181.104:8080/steve/websocket/CentralSystemService/(chargeBoxId)")
                regsview!.Steve1Check = true;
            else if (pTAConfigModel!.OCPP服务器URL == "ws://47.101.173.122:8080/steve/websocket/CentralSystemService/(chargeBoxId)")
                regsview!.Steve2Check = true;
            else if (pTAConfigModel!.OCPP服务器URL == "wss://www.evocpp.com/ocpp/evid")
                regsview!.EVSaasCheck = true;
            else if (pTAConfigModel!.OCPP服务器URL == "wss://zbox.evocpp.com/ocpp/evid")
                regsview!.ZBoxCheck = true;
            else if (!string.IsNullOrEmpty(pTAConfigModel!.OCPP服务器URL))
                regsview!.OtherIsSet = true;

            //证书进行清空
            regsview!.BookNeedWhereState = true;
        }
        else if (FTRegistersSetStatus)
        {
            var ct = (_userNeedShowControl as FTRegistersView);
            var regsview = (ct!.DataContext as FTRegistersViewModel);
            var Ft = await SerialPortConnectionViewModel.iAQBHController.AQReadData(theslaveaddr,
                (ushort)mB_FTRegisiters.Connecotr_Type1Addr, 46);   //64 * 2

            pTAConfigModel!.Connecotr_Type1!.ConnectorIndex = Ft[mB_FTRegisiters.Connecotr_Type1Addr - mB_FTRegisiters.Connecotr_Type1Addr];
            pTAConfigModel!.Connecotr_Type1!.WorkTitle = regsview!.FTRegistersList[0].ConnectorIndex != 0 ? true : false;
            pTAConfigModel!.Connecotr_Type2!.ConnectorIndex = Ft[mB_FTRegisiters.Connecotr_Type2Addr - mB_FTRegisiters.Connecotr_Type1Addr];
            pTAConfigModel!.Connecotr_Type2!.WorkTitle = regsview!.FTRegistersList[1].ConnectorIndex != 0 ? true : false;
            pTAConfigModel!.Connecotr_Type3!.ConnectorIndex = Ft[mB_FTRegisiters.Connecotr_Type3Addr - mB_FTRegisiters.Connecotr_Type1Addr];
            pTAConfigModel!.Connecotr_Type3!.WorkTitle = regsview!.FTRegistersList[2].ConnectorIndex != 0 ? true : false;
            pTAConfigModel!.Connecotr_Type1.SignalShot = Ft[mB_FTRegisiters.单枪功率_电流限制_硬件限制1地址 - mB_FTRegisiters.Connecotr_Type1Addr].ToString();
            pTAConfigModel!.Connecotr_Type2.SignalShot = Ft[mB_FTRegisiters.单枪功率_电流限制_硬件限制2地址 - mB_FTRegisiters.Connecotr_Type1Addr].ToString();
            pTAConfigModel!.Connecotr_Type3.SignalShot = Ft[mB_FTRegisiters.单枪功率_电流限制_硬件限制3地址 - mB_FTRegisiters.Connecotr_Type1Addr].ToString();

            pTAConfigModel!.直流输出最大电压能力 = Ft[mB_FTRegisiters.直流输出最大电压能力地址 - mB_FTRegisiters.Connecotr_Type1Addr].ToString();
            pTAConfigModel!.直流输出最小电压能力 = Ft[mB_FTRegisiters.直流输出最小电压能力地址 - mB_FTRegisiters.Connecotr_Type1Addr].ToString();
            pTAConfigModel!.直流输出最大电流能力 = Ft[mB_FTRegisiters.直流输出最大电流能力地址 - mB_FTRegisiters.Connecotr_Type1Addr].ToString();
            pTAConfigModel!.直流输出最小电流能力 = Ft[mB_FTRegisiters.直流输出最小电流能力地址 - mB_FTRegisiters.Connecotr_Type1Addr].ToString();
            pTAConfigModel!.交流输入额定相电压_L_N = Ft[mB_FTRegisiters.交流输入额定相电压_L_N地址 - mB_FTRegisiters.Connecotr_Type1Addr].ToString();
            pTAConfigModel!.是否启用网络安全策略 = Ft[mB_FTRegisiters.是否启用网络安全策略地址 - mB_FTRegisiters.Connecotr_Type1Addr] != 0 ? true : false;
            pTAConfigModel!.硬件是否具备水浸传感器 = Ft[mB_FTRegisiters.硬件是否具备水浸传感器地址 - mB_FTRegisiters.Connecotr_Type1Addr] != 0 ? true : false;
            pTAConfigModel!.硬件是否具备倾斜传感器 = Ft[mB_FTRegisiters.硬件是否具备倾斜传感器地址 - mB_FTRegisiters.Connecotr_Type1Addr] != 0 ? true : false;
            pTAConfigModel!.硬件是否具备烟雾传感器 = Ft[mB_FTRegisiters.硬件是否具备烟雾传感器地址 - mB_FTRegisiters.Connecotr_Type1Addr] != 0 ? true : false;
            pTAConfigModel!.硬件是否具备湿度传感器 = Ft[mB_FTRegisiters.硬件是否具备湿度传感器地址 - mB_FTRegisiters.Connecotr_Type1Addr] != 0 ? true : false;
            pTAConfigModel!.硬件是否具备POS机 = Ft[mB_FTRegisiters.硬件是否具备POS机地址 - mB_FTRegisiters.Connecotr_Type1Addr] != 0 ? true : false;
            pTAConfigModel!.硬件是否具备加热器 = Ft[mB_FTRegisiters.硬件是否具备加热器地址 - mB_FTRegisiters.Connecotr_Type1Addr] != 0 ? true : false;
            pTAConfigModel!.风扇数量 = Ft[mB_FTRegisiters.风扇数量地址 - mB_FTRegisiters.Connecotr_Type1Addr].ToString();
            switch (Ft[mB_FTRegisiters.风扇反馈类型地址 - mB_FTRegisiters.Connecotr_Type1Addr])
            {
                case 0:
                    pTAConfigModel!.风扇反馈类型1 = true;
                    break;
                case 1:
                    pTAConfigModel!.风扇反馈类型2 = true;
                    break;
                case 2:
                    pTAConfigModel!.风扇反馈类型3 = true;
                    break;
            }
            if (Ft[mB_FTRegisiters.功率分配模式地址 - mB_FTRegisiters.Connecotr_Type1Addr] == 0)
            {
                pTAConfigModel!.功率分配模式 = true;
                pTAConfigModel!.串联接触器分割的模块数量1 = Ft[mB_FTRegisiters.并联接触器分割的模块数量地址 - mB_FTRegisiters.Connecotr_Type1Addr].ToString();
                pTAConfigModel!.串联接触器分割的模块数量2 = Ft[mB_FTRegisiters.并联接触器分割的模块数量地址 - mB_FTRegisiters.Connecotr_Type1Addr + 1].ToString();
            }
            else
            {
                pTAConfigModel!.功率分配模式2 = true;
                pTAConfigModel!.并联接触器分割的模块数量1 = Ft[mB_FTRegisiters.并联接触器分割的模块数量地址 - mB_FTRegisiters.Connecotr_Type1Addr].ToString();
                pTAConfigModel!.并联接触器分割的模块数量2 = Ft[mB_FTRegisiters.并联接触器分割的模块数量地址 - mB_FTRegisiters.Connecotr_Type1Addr + 1].ToString();
                pTAConfigModel!.并联接触器分割的模块数量3 = Ft[mB_FTRegisiters.并联接触器分割的模块数量地址 - mB_FTRegisiters.Connecotr_Type1Addr + 2].ToString();
                pTAConfigModel!.并联接触器分割的模块数量4 = Ft[mB_FTRegisiters.并联接触器分割的模块数量地址 - mB_FTRegisiters.Connecotr_Type1Addr + 3].ToString();
            }
            pTAConfigModel!.直流输出最大电压能力2 = Ft[mB_FTRegisiters.直流输出最大电压能力2地址 - mB_FTRegisiters.Connecotr_Type1Addr].ToString();
            pTAConfigModel!.直流输出最小电压能力2 = Ft[mB_FTRegisiters.直流输出最小电压能力2地址 - mB_FTRegisiters.Connecotr_Type1Addr].ToString();
            pTAConfigModel!.直流输出最大电流能力2 = Ft[mB_FTRegisiters.直流输出最大电流能力2地址 - mB_FTRegisiters.Connecotr_Type1Addr].ToString();
            pTAConfigModel!.直流输出最小电流能力2 = Ft[mB_FTRegisiters.直流输出最小电流能力2地址 - mB_FTRegisiters.Connecotr_Type1Addr].ToString();
            pTAConfigModel!.触摸屏灵敏度 = Ft[mB_FTRegisiters.触摸屏灵敏度地址 - mB_FTRegisiters.Connecotr_Type1Addr];
            pTAConfigModel!.充电桩出厂序列号_需要与铭牌一致 = UShortToString(Ft,
                mB_FTRegisiters.充电桩出厂序列号_需要与铭牌一致地址 - mB_FTRegisiters.Connecotr_Type1Addr, 10, 20, false);
            pTAConfigModel!.雷达传感器 = Ft[mB_FTRegisiters.雷达传感器地址 - mB_FTRegisiters.Connecotr_Type1Addr] != 0 ? true : false;
            pTAConfigModel!.液冷泵 = Ft[mB_FTRegisiters.液冷泵地址 - mB_FTRegisiters.Connecotr_Type1Addr] != 0 ? true : false;
            pTAConfigModel!.温度传感启用 = Ft[mB_FTRegisiters.温度传感启用地址 - mB_FTRegisiters.Connecotr_Type1Addr] != 0 ? true : false;
            switch (Ft[mB_FTRegisiters.单个UU模块最大功率地址 - mB_FTRegisiters.Connecotr_Type1Addr])
            {
                case 0:
                    pTAConfigModel!.单个UU模块最大功率1 = true;
                    break;
                case 1:
                    pTAConfigModel!.单个UU模块最大功率2 = true;
                    break;
                case 2:
                    pTAConfigModel!.单个UU模块最大功率3 = true;
                    break;
            }
            pTAConfigModel!.GBT_24V辅助电源 = Ft[mB_FTRegisiters.GBT_24V辅助电源地址 - mB_FTRegisiters.Connecotr_Type1Addr] != 0 ? true : false;
            pTAConfigModel!.PTB_电表 = Ft[mB_FTRegisiters.PTB_电表地址 - mB_FTRegisiters.Connecotr_Type1Addr] != 0 ? true : false;

            regsview!.FTRegistersList[0] = pTAConfigModel!.Connecotr_Type1;
            regsview!.FTRegistersList[1] = pTAConfigModel!.Connecotr_Type2;
            regsview!.FTRegistersList[2] = pTAConfigModel!.Connecotr_Type3;

            regsview!.MaxDCVoltage = pTAConfigModel!.直流输出最大电压能力;
            regsview!.MinDCVoltage = pTAConfigModel!.直流输出最小电压能力;
            regsview!.MaxDCCurrent = pTAConfigModel!.直流输出最大电流能力;
            regsview!.MinDCCurrent = pTAConfigModel!.直流输出最小电流能力;
            regsview!.ACLN = pTAConfigModel!.交流输入额定相电压_L_N;
            regsview!.NetWorkSecurity = pTAConfigModel!.是否启用网络安全策略 ?? false;
            regsview!.WaterImmersion = pTAConfigModel!.硬件是否具备水浸传感器 ?? false;
            regsview!.Dumping = pTAConfigModel!.硬件是否具备倾斜传感器 ?? false;
            regsview!.Smog = pTAConfigModel!.硬件是否具备烟雾传感器 ?? false;
            regsview!.HumiditySensor = pTAConfigModel!.硬件是否具备湿度传感器 ?? false;
            regsview!.POS = pTAConfigModel!.硬件是否具备POS机 ?? false;
            regsview!.Heater = pTAConfigModel!.硬件是否具备加热器 ?? false;
            regsview!.NumberFans = pTAConfigModel!.风扇数量;

            regsview!.WithoutChecked = pTAConfigModel!.风扇反馈类型1 ?? false;
            regsview!.PWMChecked = pTAConfigModel!.风扇反馈类型2 ?? false;
            regsview!.RDChecked = pTAConfigModel!.风扇反馈类型3 ?? false;
            regsview!.SignaleChecked = pTAConfigModel!.功率分配模式 ?? false;
            regsview!.DuoChecked = pTAConfigModel!.功率分配模式2 ?? false;

            if (regsview!.SignaleChecked)
            {
                regsview!.DuoMode1 = string.Empty;
                regsview!.DuoMode2 = string.Empty;
                regsview!.DuoMode3 = string.Empty;
                regsview!.DuoMode4 = string.Empty;

                regsview!.SignalMode1 = pTAConfigModel!.串联接触器分割的模块数量1!;
                regsview!.SignalMode2 = pTAConfigModel!.串联接触器分割的模块数量2!;

               
            }
            else
            {
                regsview!.DuoMode1 = pTAConfigModel!.并联接触器分割的模块数量1!;
                regsview!.DuoMode2 = pTAConfigModel!.并联接触器分割的模块数量2!;
                regsview!.DuoMode3 = pTAConfigModel!.并联接触器分割的模块数量3!;
                regsview!.DuoMode4 = pTAConfigModel!.并联接触器分割的模块数量4!;

                regsview!.SignalMode1 = string.Empty;
                regsview!.SignalMode2 = string.Empty;
            }

            regsview!.MaxDCVoltageGun2 = pTAConfigModel!.直流输出最大电压能力2!;
            regsview!.MinDCVoltageGun2 = pTAConfigModel!.直流输出最小电压能力2!;
            regsview!.MaxDCCurrentGun2 = pTAConfigModel!.直流输出最大电流能力2!;
            regsview!.MinDCCurrentGun2 = pTAConfigModel!.直流输出最小电流能力2!;
            regsview!.TouchScreenSensitivity = pTAConfigModel!.触摸屏灵敏度 ?? 0;
            regsview!.SerialNumber = pTAConfigModel!.充电桩出厂序列号_需要与铭牌一致;
            regsview!.RadarSensor = pTAConfigModel!.雷达传感器 ?? false;
            regsview!.LiquidCoolingPump = pTAConfigModel!.液冷泵 ?? false;
            regsview!.TempSensor = pTAConfigModel!.温度传感启用 ?? false;
            regsview!.SignaleWind_1 = pTAConfigModel!.单个UU模块最大功率1 ?? false;
            regsview!.SignaleWind_2 = pTAConfigModel!.单个UU模块最大功率2 ?? false;
            regsview!.SignaleWind_3 = pTAConfigModel!.单个UU模块最大功率3 ?? false;
            regsview!.GBTHelpVoltage = pTAConfigModel!.GBT_24V辅助电源 ?? false;
            regsview!.PTBElc = pTAConfigModel!.PTB_电表! ?? false;
            await ChangeTheProcess((int)mB_FTRegisiters.PTB_电表地址, (int)mB_FTRegisiters.PTB_电表地址);
        }

    }
    public static string UShortToString(ushort[] datalist,int start, int end, int length, bool jshu)
    {
        byte[] regs = new byte[length];
        Buffer.BlockCopy(datalist.Skip(start).Take(end).ToArray(), 0, regs, 0, regs.Length);
        // Swap the bytes of each ushort in the byte array
        int pick = jshu ? 1 : 0;
        for (int i = 0; i < regs.Length - pick; i += 2)
        {
            byte temp = regs[i];
            regs[i] = regs[i + 1];
            regs[i + 1] = temp;
        }
        // Convert the modified byte array to a string using ASCII encoding
        var ust = Encoding.ASCII.GetString(regs);
        return ust.Split("\0").FirstOrDefault()!;
    }
    public static ushort[] StrignToUShort(string data, int length, bool jshu)
    {
        byte[] bytereg = Encoding.ASCII.GetBytes(data);
        int pick;
        if (bytereg.Length % 2 != 0)
            pick = 1;
        else
            pick = 0;

        for (int i = 0; i < length - pick; i += 2)
        {
            byte temp = bytereg[i];
            bytereg[i] = bytereg[i + 1];
            bytereg[i + 1] = temp;
        }
        ushort[] regs = new ushort[length];
        Buffer.BlockCopy(bytereg, 0, regs, 0, data.Length);

        return regs;
    }
    public class HelpWithRegFunction{
        public ushort[] data { set; get; }
        public ushort regaddr { get; set; }
    }
    public static PTAConfigModel pTAConfigModel { get; set; } = new();
    private async Task SetConfigCommandFunc()
    {
        if (!SerialPortConnectionViewModel._joinCommand)
        {
            var uiMessageBox = new Wpf.Ui.Controls.MessageBox
            {
                Title = "Error",
                Content = "Please Open Serial Port First.",
            };
            var result = uiMessageBox.ShowDialogAsync();
            return;
        }
        await ChangeTheProcess(0, 1);
        await TakeStartOrEnd(false);
        await Task.Delay(100);
        if (UserSetStatus)
        {
            List<HelpWithRegFunction> helpWithRegFunction = new();
            var ct = (_userNeedShowControl as UserRegistersView);
            var regsview = (ct!.DataContext as UserRegistersViewModel);
            try
            {
                #region 保存当前变更的配置， 配置拉过来存
                pTAConfigModel!.用户密码 = regsview!.UserPassword;
                pTAConfigModel!.Modbus = regsview!.ModbusAddress;
                pTAConfigModel.RS485波特率 = regsview!.RS485Baud;
                pTAConfigModel.Mac充电是否启动 = regsview!.MacCharging;
                pTAConfigModel.POS是否启动 = regsview!.PosCharing;
                pTAConfigModel.DC枪兼容充电模式是否启用 = regsview!.DC_Complatible_Charging;
                pTAConfigModel.AC枪兼容充电模式是否启用 = regsview!.AC_Complatible_Charging;
                pTAConfigModel.货币单位精度 = regsview!.Currency_Unit_Precision;
                pTAConfigModel.POS金额单位 = regsview!.PosAmountUnit;
                pTAConfigModel.POS预扣款金额 = regsview!.PosWithholdingAmount;
                pTAConfigModel.单位电价每kwh的价格 = regsview!.ElecPrice;
                pTAConfigModel.单位小时服务费 = regsview!.ServiceCharge;
                pTAConfigModel.遥测数据设置 = regsview!.Enable_the_Second_Platform;
                pTAConfigModel.LCD第一语言 = regsview!.LDCLangurageFirst;
                pTAConfigModel.LCD第二语言 = regsview!.LDCLangurageSecond;
                pTAConfigModel.是否启用自动使用MAC充电 = regsview!.AutomaticChargingforMac;
                pTAConfigModel.屏幕右下角的文字 = regsview!.ShowScreen;
                pTAConfigModel.MAC上报格式 = regsview!.MacReportFormat;
                pTAConfigModel.RFID是否禁用 = regsview!.Disabled_RFID;
                pTAConfigModel.是否锁定使用UTC时间 = regsview!.LockToUseUtcTime;
                pTAConfigModel.直接按键停止充电使能 = regsview!.PressButtonToStopCharging;
                pTAConfigModel.OCPP遥测服务器URL_CPID = regsview!.OCPPCheckData;

                pTAConfigModel.OCPP遥测服务器HTTP身份校验使能 = regsview!.OCPPUserInit;
                pTAConfigModel.OCPP遥测服务器HTTP身份校验用户名 = regsview!.OCPPUserName;
                pTAConfigModel.OCPP遥测服务器HTTP身份校验密码 = regsview!.OCPPUserPassword;
                pTAConfigModel.是否禁止未插枪远程鉴权 = regsview!.ForbidAuthorizeInUnplug;
                pTAConfigModel.离线IC卡允许在OCPP模式下进行本地缓存校验 = regsview!.Offline_IC_CardLocal_Authorization;
                pTAConfigModel.PE检测是否禁用 = regsview!.DisablePE;
                pTAConfigModel.时间 = regsview!.EquipTime;
                pTAConfigModel.离线IC卡号1 = regsview!.Offline_Card_1;
                pTAConfigModel.离线IC卡号2 = regsview!.Offline_Card_2;
                pTAConfigModel.离线IC卡号3 = regsview!.Offline_Card_3;
                pTAConfigModel.离线IC卡号4 = regsview!.Offline_Card_4;
                pTAConfigModel.离线IC卡号5 = regsview!.Offline_Card_5;
                pTAConfigModel.禁用服务器时间来校准充电桩 = regsview!.Calibrating_EVSE_Using_ServerTime;
                pTAConfigModel.Bootnotification在每次重新连接服务器后都会重新发送一次 = regsview!.Retransmit_Notifications_on_Reconnect;
                pTAConfigModel.Heart总是根据配置项定时发送_不受Websocket的ping_pong影响 = regsview!.Scheduled_Heartbeat_Sending;
                pTAConfigModel.是否启用Modbus临时功率限制 = regsview!.ModbusLimit;
                pTAConfigModel.是否启用离线充电模式下即插即用 = regsview!.Enable_plug;
                pTAConfigModel.是否启用OCPP延迟连接 = regsview!.Delayed_Connection;
                pTAConfigModel.POS机启动的数据不经过OCPP平台_当POS机启动充电的时候_枪头会变为unavaliable = regsview!.No_Pass_OCPP;
                pTAConfigModel.地锁支持 = regsview!.Ground_Lock_Support;
                pTAConfigModel.自动使用MAC充电倒计时秒数 = regsview!.Automatic_MAC_Charging_Countdown_in_Seconds;
                pTAConfigModel.服务费单位 = regsview!.ServiceFeeUnit;
                pTAConfigModel.LCD视频广告播放策略 = regsview!.SelLCDOpenLogical;
                pTAConfigModel.LCD视频广告存放位置 = regsview!.SelLCDOpenAddr;
                pTAConfigModel.LCD视频广告存放数量 = regsview!.SelLCDOpenAccount;
                pTAConfigModel.充电桩启动充电过程异常_是上报suspend还是上报_fault = regsview!.SelErrorStartElecMsg;
                pTAConfigModel.是否允许充电桩未插枪本地刷卡_无按钮_插枪界面允许直接刷卡鉴权 = regsview!.No_Pass_Clash;
                pTAConfigModel.OfflineMeterValue_禁用 = regsview!.OfflineMaterValue;
                pTAConfigModel.每次断网重连后_StatusNotification_发送逻辑设定 = regsview!.SelRestartLine;
                pTAConfigModel.充电启动失败后是否自动恢复到Available或Preparing状态 = regsview!.SelCharging_Start_Failure;

                pTAConfigModel!.用户密码 = 5 > pTAConfigModel!.用户密码.Length ? pTAConfigModel!.用户密码.PadRight(5, '\0') : pTAConfigModel!.用户密码;
                pTAConfigModel!.屏幕右下角的文字 = 10 > pTAConfigModel!.屏幕右下角的文字.Length ? pTAConfigModel!.屏幕右下角的文字.PadRight(10, '\0') : pTAConfigModel!.屏幕右下角的文字;
                pTAConfigModel!.OCPP遥测服务器URL_CPID = 128 > pTAConfigModel!.OCPP遥测服务器URL_CPID.Length ? pTAConfigModel!.OCPP遥测服务器URL_CPID.PadRight(128, '\0') : pTAConfigModel!.OCPP遥测服务器URL_CPID;
                pTAConfigModel!.OCPP遥测服务器HTTP身份校验用户名 = 25 > pTAConfigModel!.OCPP遥测服务器HTTP身份校验用户名.Length ? pTAConfigModel!.OCPP遥测服务器HTTP身份校验用户名.PadRight(25, '\0') : pTAConfigModel!.OCPP遥测服务器HTTP身份校验用户名;
                pTAConfigModel!.OCPP遥测服务器HTTP身份校验密码 = 25 > pTAConfigModel!.OCPP遥测服务器HTTP身份校验密码.Length ? pTAConfigModel!.OCPP遥测服务器HTTP身份校验密码.PadRight(25, '\0') : pTAConfigModel!.OCPP遥测服务器HTTP身份校验密码;

                pTAConfigModel!.离线IC卡号1 = 10 > pTAConfigModel!.离线IC卡号1.Length ? pTAConfigModel!.离线IC卡号1.PadRight(10, '\0') : pTAConfigModel!.离线IC卡号1;
                pTAConfigModel!.离线IC卡号2 = 50 > pTAConfigModel!.离线IC卡号2.Length ? pTAConfigModel!.离线IC卡号2.PadRight(10, '\0') : pTAConfigModel!.离线IC卡号2;
                pTAConfigModel!.离线IC卡号3 = 50 > pTAConfigModel!.离线IC卡号3.Length ? pTAConfigModel!.离线IC卡号3.PadRight(10, '\0') : pTAConfigModel!.离线IC卡号3;
                pTAConfigModel!.离线IC卡号4 = 50 > pTAConfigModel!.离线IC卡号4.Length ? pTAConfigModel!.离线IC卡号4.PadRight(10, '\0') : pTAConfigModel!.离线IC卡号4;
                pTAConfigModel!.离线IC卡号5 = 50 > pTAConfigModel!.离线IC卡号5.Length ? pTAConfigModel!.离线IC卡号5.PadRight(10, '\0') : pTAConfigModel!.离线IC卡号5;
                #endregion
                if (!string.IsNullOrEmpty(pTAConfigModel!.用户密码))
                {
                    helpWithRegFunction.Add(new HelpWithRegFunction
                    {
                        data = StrignToUShort(pTAConfigModel!.用户密码!, 5, false),
                        regaddr = (ushort)mB_UserRegisiters.用户密码地址
                    });
                }
                if (!string.IsNullOrEmpty(pTAConfigModel!.Modbus))
                {
                    helpWithRegFunction.Add(new HelpWithRegFunction
                    {
                        data = [ushort.Parse(pTAConfigModel!.Modbus)],
                        regaddr = (ushort)mB_UserRegisiters.Modbus地址
                    });
                }
                if (pTAConfigModel!.RS485波特率 != -1)
                {
                    helpWithRegFunction.Add(new HelpWithRegFunction
                    {
                        data = [(ushort)(pTAConfigModel!.RS485波特率)],
                        regaddr = (ushort)mB_UserRegisiters.RS485波特率地址
                    });
                }
                helpWithRegFunction.Add(new HelpWithRegFunction
                {
                    data = [(ushort)(pTAConfigModel!.Mac充电是否启动.Value ? 1 : 0)],
                    regaddr = (ushort)mB_UserRegisiters.Mac充电是否启动地址
                });
                helpWithRegFunction.LastOrDefault()!.data = helpWithRegFunction.LastOrDefault()!.data.Concat([(ushort)(pTAConfigModel!.POS是否启动.Value ? 1 : 0)]).ToArray();
                helpWithRegFunction.LastOrDefault()!.data = helpWithRegFunction.LastOrDefault()!.data.Concat([(ushort)(pTAConfigModel!.DC枪兼容充电模式是否启用.Value ? 1 : 0)]).ToArray();
                helpWithRegFunction.LastOrDefault()!.data = helpWithRegFunction.LastOrDefault()!.data.Concat([(ushort)(pTAConfigModel!.AC枪兼容充电模式是否启用.Value ? 1 : 0)]).ToArray();

                if (pTAConfigModel!.POS预扣款金额 != "")
                {
                    var d = (ushort)(double.Parse(pTAConfigModel!.POS预扣款金额) * 1000);
                    helpWithRegFunction.Add(new HelpWithRegFunction
                    {
                        data = ConvertUintToUShortArray(d),
                        regaddr = (ushort)mB_UserRegisiters.POS预扣款金额地址
                    });
                }
                helpWithRegFunction.Add(new HelpWithRegFunction
                {
                    data = StrignToUShort(pTAConfigModel!.POS金额单位, 2, false),
                    regaddr = (ushort)mB_UserRegisiters.POS金额单位地址
                });
                if (pTAConfigModel!.单位电价每kwh的价格 != "")
                {
                    var d = (uint)(double.Parse(pTAConfigModel!.单位电价每kwh的价格) * Math.Pow(10, int.Parse(pTAConfigModel!.货币单位精度)));
                    helpWithRegFunction.Add(new HelpWithRegFunction
                    {
                        data = ConvertUintToUShortArray(d),
                        regaddr = (ushort)mB_UserRegisiters.单位电价每kwh的价格地址
                    });
                }
                if (pTAConfigModel!.单位小时服务费 != "")
                {
                    var d = (uint)(double.Parse(pTAConfigModel!.单位小时服务费) * Math.Pow(10, int.Parse(pTAConfigModel!.货币单位精度)));
                    helpWithRegFunction.Add(new HelpWithRegFunction
                    {
                        data = ConvertUintToUShortArray(d),
                        regaddr = (ushort)mB_UserRegisiters.单位小时服务费地址
                    });
                }
                helpWithRegFunction.Add(new HelpWithRegFunction
                {
                    data = [(ushort)(pTAConfigModel!.遥测数据设置.Value ? 1 : 0)],
                    regaddr = (ushort)mB_UserRegisiters.遥测数据设置地址
                });

                helpWithRegFunction.LastOrDefault()!.data = helpWithRegFunction.LastOrDefault()!.data.Concat([(ushort)pTAConfigModel!.LCD第一语言]).ToArray();
                helpWithRegFunction.LastOrDefault()!.data = helpWithRegFunction.LastOrDefault()!.data.Concat([(ushort)pTAConfigModel!.LCD第二语言]).ToArray();
                helpWithRegFunction.LastOrDefault()!.data = helpWithRegFunction.LastOrDefault()!.data.Concat([(ushort)(pTAConfigModel!.是否启用自动使用MAC充电.Value ? 1 : 0)]).ToArray();

                if (!string.IsNullOrEmpty(pTAConfigModel!.屏幕右下角的文字))
                {
                    helpWithRegFunction.Add(new HelpWithRegFunction
                    {
                        data = StrignToUShort(pTAConfigModel!.屏幕右下角的文字, 10, false),
                        regaddr = (ushort)mB_UserRegisiters.屏幕右下角的文字地址
                    });
                }
                helpWithRegFunction.Add(new HelpWithRegFunction
                {
                    data = [(ushort)pTAConfigModel!.MAC上报格式],
                    regaddr = (ushort)mB_UserRegisiters.MAC上报格式地址
                });
                helpWithRegFunction.LastOrDefault()!.data = helpWithRegFunction.LastOrDefault()!.data.Concat([(ushort)(pTAConfigModel!.RFID是否禁用.Value ? 1 : 0)]).ToArray();
                helpWithRegFunction.LastOrDefault()!.data = helpWithRegFunction.LastOrDefault()!.data.Concat([(ushort)(pTAConfigModel!.是否锁定使用UTC时间.Value ? 1 : 0)]).ToArray();
                helpWithRegFunction.LastOrDefault()!.data = helpWithRegFunction.LastOrDefault()!.data.Concat([(ushort)(pTAConfigModel!.直接按键停止充电使能.Value ? 1 : 0)]).ToArray();

                //128字节
                if (!string.IsNullOrEmpty(pTAConfigModel!.OCPP遥测服务器URL_CPID))
                {
                    helpWithRegFunction.Add(new HelpWithRegFunction
                    {
                        data = StrignToUShort(pTAConfigModel!.OCPP遥测服务器URL_CPID.Substring(0, 123), 123, true),
                        regaddr = (ushort)mB_UserRegisiters.OCPP遥测服务器URL_CPID地址
                    });
                    helpWithRegFunction.Add(new HelpWithRegFunction
                    {
                        data = StrignToUShort(pTAConfigModel!.OCPP遥测服务器URL_CPID.Substring(123), 5, true),
                        regaddr = (ushort)mB_UserRegisiters.OCPP遥测服务器URL_CPID地址 + 123
                    });
                }
                helpWithRegFunction.Add(new HelpWithRegFunction
                {
                    data = [(ushort)(pTAConfigModel!.OCPP遥测服务器HTTP身份校验使能.Value ? 1 : 0)],
                    regaddr = (ushort)mB_UserRegisiters.OCPP遥测服务器HTTP身份校验使能地址
                });

                if (pTAConfigModel!.OCPP遥测服务器HTTP身份校验使能.Value)
                {
                    helpWithRegFunction.Add(new HelpWithRegFunction
                    {
                        data = StrignToUShort(pTAConfigModel!.OCPP遥测服务器HTTP身份校验用户名, 25, true),
                        regaddr = (ushort)mB_UserRegisiters.OCPP遥测服务器HTTP身份校验用户名地址
                    });

                    helpWithRegFunction.Add(new HelpWithRegFunction
                    {
                        data = StrignToUShort(pTAConfigModel!.OCPP遥测服务器HTTP身份校验密码, 25, true),
                        regaddr = (ushort)mB_UserRegisiters.OCPP遥测服务器HTTP身份校验密码地址
                    });
                }
                helpWithRegFunction.Add(new HelpWithRegFunction
                {
                    data = [(ushort)(pTAConfigModel!.是否禁止未插枪远程鉴权.Value ? 1 : 0)],
                    regaddr = (ushort)mB_UserRegisiters.是否禁止未插枪远程鉴权地址
                });
                helpWithRegFunction.LastOrDefault()!.data = helpWithRegFunction.LastOrDefault()!.data.Concat([(ushort)(pTAConfigModel!.离线IC卡允许在OCPP模式下进行本地缓存校验.Value ? 1 : 0)]).ToArray();
                helpWithRegFunction.LastOrDefault()!.data = helpWithRegFunction.LastOrDefault()!.data.Concat([(ushort)(pTAConfigModel!.PE检测是否禁用.Value ? 1 : 0)]).ToArray();
                //helpWithRegFunction.Add(new HelpWithRegFunction
                //{
                //    data = [(ushort)(pTAConfigModel!.离线IC卡允许在OCPP模式下进行本地缓存校验.Value ? 1 : 0)],
                //    regaddr = (ushort)mB_UserRegisiters.离线IC卡允许在OCPP模式下进行本地缓存校验地址
                //});
                //helpWithRegFunction.Add(new HelpWithRegFunction
                //{
                //    data = [(ushort)(pTAConfigModel!.PE检测是否禁用.Value ? 1 : 0)],
                //    regaddr = (ushort)mB_UserRegisiters.PE检测是否禁用地址
                //});
                #region 填时间
                try
                {
                    var taketime = DateTime.Parse(pTAConfigModel!.时间);
                    helpWithRegFunction.Add(new HelpWithRegFunction
                    {
                        data = [(ushort)(taketime.Year % 100)],
                        regaddr = (ushort)mB_UserRegisiters.时间地址
                    });
                    helpWithRegFunction.Add(new HelpWithRegFunction
                    {
                        data = [(ushort)(taketime.Month)],
                        regaddr = (ushort)mB_UserRegisiters.时间地址 + 1
                    });
                    helpWithRegFunction.Add(new HelpWithRegFunction
                    {
                        data = [(ushort)(taketime.Day)],
                        regaddr = (ushort)mB_UserRegisiters.时间地址 + 2
                    });
                    helpWithRegFunction.Add(new HelpWithRegFunction
                    {
                        data = [(ushort)(taketime.Hour)],
                        regaddr = (ushort)mB_UserRegisiters.时间地址 + 3
                    });
                    helpWithRegFunction.Add(new HelpWithRegFunction
                    {
                        data = [(ushort)(taketime.Minute)],
                        regaddr = (ushort)mB_UserRegisiters.时间地址 + 4
                    });
                    helpWithRegFunction.Add(new HelpWithRegFunction
                    {
                        data = [(ushort)(taketime.Second)],
                        regaddr = (ushort)mB_UserRegisiters.时间地址 + 5
                    });
                }
                catch { }
                #endregion
                //根据十进制发送6位数据
                if (!string.IsNullOrEmpty(pTAConfigModel!.离线IC卡号1))
                {
                    helpWithRegFunction.Add(new HelpWithRegFunction
                    {
                        data = StrignToUShort(pTAConfigModel!.离线IC卡号1, 10, false),
                        regaddr = (ushort)mB_UserRegisiters.离线IC卡号1地址
                    });
                }
                if (!string.IsNullOrEmpty(regsview!.Offline_Card_2))
                {
                    helpWithRegFunction.Add(new HelpWithRegFunction
                    {
                        data = StrignToUShort(pTAConfigModel!.离线IC卡号2, 10, false),
                        regaddr = (ushort)mB_UserRegisiters.离线IC卡号2地址
                    });
                }
                if (!string.IsNullOrEmpty(regsview!.Offline_Card_3))
                {
                    helpWithRegFunction.Add(new HelpWithRegFunction
                    {
                        data = StrignToUShort(pTAConfigModel!.离线IC卡号3, 10, false),
                        regaddr = (ushort)mB_UserRegisiters.离线IC卡号3地址
                    });
                }
                if (!string.IsNullOrEmpty(regsview!.Offline_Card_4))
                {
                    helpWithRegFunction.Add(new HelpWithRegFunction
                    {
                        data = StrignToUShort(pTAConfigModel!.离线IC卡号4, 10, false),
                        regaddr = (ushort)mB_UserRegisiters.离线IC卡号4地址
                    });
                }
                if (!string.IsNullOrEmpty(regsview!.Offline_Card_5))
                {
                    helpWithRegFunction.Add(new HelpWithRegFunction
                    {
                        data = StrignToUShort(pTAConfigModel!.离线IC卡号5, 10, false),
                        regaddr = (ushort)mB_UserRegisiters.离线IC卡号5地址
                    });
                }
                helpWithRegFunction.Add(new HelpWithRegFunction
                {
                    data = [(ushort)(pTAConfigModel!.禁用服务器时间来校准充电桩.Value ? 1 : 0)],
                    regaddr = (ushort)mB_UserRegisiters.禁用服务器时间来校准充电桩地址
                });
                helpWithRegFunction.LastOrDefault()!.data = helpWithRegFunction.LastOrDefault()!.data.Concat([(ushort)(pTAConfigModel!.Bootnotification在每次重新连接服务器后都会重新发送一次.Value ? 1 : 0)]).ToArray();
                helpWithRegFunction.LastOrDefault()!.data = helpWithRegFunction.LastOrDefault()!.data.Concat([(ushort)(pTAConfigModel!.Heart总是根据配置项定时发送_不受Websocket的ping_pong影响.Value ? 1 : 0)]).ToArray();
                if (pTAConfigModel!.是否启用Modbus临时功率限制 != -1)
                {
                    helpWithRegFunction.Add(new HelpWithRegFunction
                    {
                        data = [(ushort)pTAConfigModel!.是否启用Modbus临时功率限制],
                        regaddr = (ushort)mB_UserRegisiters.是否启用Modbus临时功率限制地址
                    });
                }
                helpWithRegFunction.Add(new HelpWithRegFunction
                {
                    data = [(ushort)(pTAConfigModel!.是否启用离线充电模式下即插即用.Value ? 1 : 0)],
                    regaddr = (ushort)mB_UserRegisiters.是否启用离线充电模式下即插即用地址
                });
                helpWithRegFunction.LastOrDefault()!.data = helpWithRegFunction.LastOrDefault()!.data.Concat([(ushort)(pTAConfigModel!.是否启用OCPP延迟连接.Value ? 1 : 0)]).ToArray();
                helpWithRegFunction.LastOrDefault()!.data = helpWithRegFunction.LastOrDefault()!.data.Concat([(ushort)(pTAConfigModel!.POS机启动的数据不经过OCPP平台_当POS机启动充电的时候_枪头会变为unavaliable.Value ? 1 : 0)]).ToArray();
                helpWithRegFunction.LastOrDefault()!.data = helpWithRegFunction.LastOrDefault()!.data.Concat([(ushort)(pTAConfigModel!.地锁支持.Value ? 1 : 0)]).ToArray();

                if (pTAConfigModel!.自动使用MAC充电倒计时秒数 != "")
                {
                    helpWithRegFunction.Add(new HelpWithRegFunction
                    {
                        data = [ushort.Parse(pTAConfigModel!.自动使用MAC充电倒计时秒数)],
                        regaddr = (ushort)mB_UserRegisiters.自动使用MAC充电倒计时秒数地址
                    });
                }
                helpWithRegFunction.Add(new HelpWithRegFunction
                {
                    data = [(ushort)pTAConfigModel!.服务费单位],
                    regaddr = (ushort)mB_UserRegisiters.服务费单位地址
                });
                helpWithRegFunction.LastOrDefault()!.data = helpWithRegFunction.LastOrDefault()!.data.Concat([ushort.Parse(pTAConfigModel!.货币单位精度)]).ToArray();
                helpWithRegFunction.LastOrDefault()!.data = helpWithRegFunction.LastOrDefault()!.data.Concat([(ushort)pTAConfigModel!.LCD视频广告播放策略]).ToArray();
                helpWithRegFunction.LastOrDefault()!.data = helpWithRegFunction.LastOrDefault()!.data.Concat([(ushort)pTAConfigModel!.LCD视频广告存放位置]).ToArray();
                if (!string.IsNullOrEmpty(pTAConfigModel!.LCD视频广告存放数量))
                {
                    helpWithRegFunction.LastOrDefault()!.data = helpWithRegFunction.LastOrDefault()!.data.Concat([ushort.Parse(pTAConfigModel!.LCD视频广告存放数量)]).ToArray();
                }

                helpWithRegFunction.LastOrDefault()!.data = helpWithRegFunction.LastOrDefault()!.data.Concat([(ushort)pTAConfigModel!.充电桩启动充电过程异常_是上报suspend还是上报_fault]).ToArray();
                helpWithRegFunction.LastOrDefault()!.data = helpWithRegFunction.LastOrDefault()!.data.Concat([(ushort)(pTAConfigModel!.是否允许充电桩未插枪本地刷卡_无按钮_插枪界面允许直接刷卡鉴权.Value ? 1 : 0)]).ToArray();
                helpWithRegFunction.LastOrDefault()!.data = helpWithRegFunction.LastOrDefault()!.data.Concat([(ushort)(pTAConfigModel!.OfflineMeterValue_禁用.Value ? 1 : 0)]).ToArray();
                helpWithRegFunction.LastOrDefault()!.data = helpWithRegFunction.LastOrDefault()!.data.Concat([(ushort)pTAConfigModel!.每次断网重连后_StatusNotification_发送逻辑设定]).ToArray();
                helpWithRegFunction.LastOrDefault()!.data = helpWithRegFunction.LastOrDefault()!.data.Concat([(ushort)pTAConfigModel!.充电启动失败后是否自动恢复到Available或Preparing状态]).ToArray();

                foreach (var help in helpWithRegFunction)
                {
                    int index = helpWithRegFunction.IndexOf(help);
                    //如果我的slave id 变更了，我该如何得治
                    await SerialPortConnectionViewModel.
                        iAQBHController.AQBHSendData(theslaveaddr, help.regaddr, help.data);
                    //搞一个进度条转圈
                    await ChangeTheProcess(index, helpWithRegFunction.Count());
                }
                await ChangeTheProcess(1, 1);
            }
            catch(Exception ex) {
                var uiMessageBox = new Wpf.Ui.Controls.MessageBox
                {
                    Title = "String Format Error",
                    Content =
                    SetLanguage(globellanguage, "EmptyTroubleMessage")
                };
                var result = await uiMessageBox.ShowDialogAsync();
                await TakeStartOrEnd(false);
                await ChangeTheProcess(1, 1);
                return;
            }
        }
        else if (NetWorkSetStatus)
        {
            try
            {
                List<HelpWithRegFunction> helpWithRegFunction = new();
                var ct = (_userNeedShowControl as NetworkRegisiterView);
                var regsview = (ct!.DataContext as NetWorkRegisterViewModel);
                #region 读取界面UI数据
                pTAConfigModel!.离线模式使能 = regsview!.OfflineChecked;
                pTAConfigModel!.自动切换网络 = regsview!.AutomaticChecked;
                pTAConfigModel!.以太网启用 = regsview!.EtherNetChecked;
                pTAConfigModel!.WIFI启用 = regsview!.WIFIChecked;
                pTAConfigModel!.LTE启用 = regsview!.FourGChecked;
                pTAConfigModel!.WIFI_SSID = regsview!.WifiSSID;
                pTAConfigModel!.WIFI密码 = regsview!.WifiPassword;
                pTAConfigModel!.APN = regsview!.APNAddress;
                pTAConfigModel!.APN_User = regsview!.APNUserName;
                pTAConfigModel!.APN_Password = regsview!.APNPassword;
                pTAConfigModel!.静态IP使能 = regsview!.EnableEtherNetIPState;
                pTAConfigModel!.静态IP = regsview!.IPAddress;
                pTAConfigModel!.默认网关 = regsview!.IPMask;
                pTAConfigModel!.子网掩码 = regsview!.DefaultGetWay;
                pTAConfigModel!.自定义DNS = regsview!.AutoDNSInit;
                pTAConfigModel!.自定义首选DNS = regsview!.DNSFirst;
                pTAConfigModel!.自定义备用DNS = regsview!.DNSSecond;

                pTAConfigModel!.WIFI_SSID = 15 > pTAConfigModel!.WIFI_SSID.Length ? pTAConfigModel!.WIFI_SSID.PadRight(15, '\0') : pTAConfigModel!.WIFI_SSID;
                pTAConfigModel!.WIFI密码 = 15 > pTAConfigModel!.WIFI密码.Length ? pTAConfigModel!.WIFI密码.PadRight(15, '\0') : pTAConfigModel!.WIFI密码;
                pTAConfigModel!.APN = 15 > pTAConfigModel!.APN.Length ? pTAConfigModel!.APN.PadRight(15, '\0') : pTAConfigModel!.APN;
                pTAConfigModel!.APN_User = 15 > pTAConfigModel!.APN_User.Length ? pTAConfigModel!.APN_User.PadRight(15, '\0') : pTAConfigModel!.APN_User;
                pTAConfigModel!.APN_Password = 15 > pTAConfigModel!.APN_Password.Length ? pTAConfigModel!.APN_Password.PadRight(15, '\0') : pTAConfigModel!.APN_Password;
                pTAConfigModel!.静态IP = 4 > pTAConfigModel!.静态IP.Length ? pTAConfigModel!.静态IP.PadRight(4, '\0') : pTAConfigModel!.静态IP;
                pTAConfigModel!.默认网关 = 4 > pTAConfigModel!.默认网关.Length ? pTAConfigModel!.默认网关.PadRight(4, '\0') : pTAConfigModel!.默认网关;
                pTAConfigModel!.子网掩码 = 4 > pTAConfigModel!.子网掩码.Length ? pTAConfigModel!.子网掩码.PadRight(4, '\0') : pTAConfigModel!.子网掩码;
                pTAConfigModel!.自定义首选DNS = 4 > pTAConfigModel!.自定义首选DNS.Length ? pTAConfigModel!.自定义首选DNS.PadRight(4, '\0') : pTAConfigModel!.自定义首选DNS;
                pTAConfigModel!.自定义备用DNS = 4 > pTAConfigModel!.自定义备用DNS.Length ? pTAConfigModel!.自定义备用DNS.PadRight(4, '\0') : pTAConfigModel!.自定义备用DNS;
                #endregion
                helpWithRegFunction.Add(new HelpWithRegFunction
                {
                    data = [(ushort)(pTAConfigModel!.离线模式使能.Value ? 1 : 0)],
                    regaddr = (ushort)mB_NetWorkRegisiters.离线模式使能地址
                });
                helpWithRegFunction.LastOrDefault()!.data = helpWithRegFunction.LastOrDefault()!.data.Concat([(ushort)(pTAConfigModel!.自动切换网络.Value ? 1 : 0)]).ToArray();
                helpWithRegFunction.LastOrDefault()!.data = helpWithRegFunction.LastOrDefault()!.data.Concat([(ushort)(pTAConfigModel!.以太网启用.Value ? 1 : 0)]).ToArray();
                helpWithRegFunction.LastOrDefault()!.data = helpWithRegFunction.LastOrDefault()!.data.Concat([(ushort)(pTAConfigModel!.WIFI启用.Value ? 1 : 0)]).ToArray();
                helpWithRegFunction.LastOrDefault()!.data = helpWithRegFunction.LastOrDefault()!.data.Concat([(ushort)(pTAConfigModel!.LTE启用.Value ? 1 : 0)]).ToArray();
                helpWithRegFunction.LastOrDefault()!.data = helpWithRegFunction.LastOrDefault()!.data.Concat(
                    StrignToUShort(pTAConfigModel!.WIFI_SSID!, 15, false)
                    
                    ).ToArray();
                helpWithRegFunction.LastOrDefault()!.data = helpWithRegFunction.LastOrDefault()!.data.Concat(StrignToUShort(pTAConfigModel!.WIFI密码!, 15, false)).ToArray();
                helpWithRegFunction.LastOrDefault()!.data = helpWithRegFunction.LastOrDefault()!.data.Concat(StrignToUShort(pTAConfigModel!.APN!, 15, false)).ToArray();
                helpWithRegFunction.LastOrDefault()!.data = helpWithRegFunction.LastOrDefault()!.data.Concat(StrignToUShort(pTAConfigModel!.APN_User!, 15, false)).ToArray();
                helpWithRegFunction.LastOrDefault()!.data = helpWithRegFunction.LastOrDefault()!.data.Concat(StrignToUShort(pTAConfigModel!.APN_Password!, 15, false)).ToArray();
                helpWithRegFunction.LastOrDefault()!.data = helpWithRegFunction.LastOrDefault()!.data.Concat([(ushort)(pTAConfigModel!.静态IP使能.Value ? 1 : 0)]).ToArray();


                helpWithRegFunction.LastOrDefault()!.data = helpWithRegFunction.LastOrDefault()!.data.Concat(SplitAddr(pTAConfigModel!.静态IP)).ToArray();
                helpWithRegFunction.LastOrDefault()!.data = helpWithRegFunction.LastOrDefault()!.data.Concat(SplitAddr(pTAConfigModel!.默认网关)).ToArray();
                helpWithRegFunction.LastOrDefault()!.data = helpWithRegFunction.LastOrDefault()!.data.Concat(SplitAddr(pTAConfigModel!.子网掩码)).ToArray();
                helpWithRegFunction.LastOrDefault()!.data = helpWithRegFunction.LastOrDefault()!.data.Concat([(ushort)(pTAConfigModel!.自定义DNS.Value ? 1 : 0)]).ToArray();
                helpWithRegFunction.LastOrDefault()!.data = helpWithRegFunction.LastOrDefault()!.data.Concat(SplitAddr(pTAConfigModel!.自定义首选DNS)).ToArray();
                helpWithRegFunction.LastOrDefault()!.data = helpWithRegFunction.LastOrDefault()!.data.Concat(SplitAddr(pTAConfigModel!.自定义备用DNS)).ToArray();

                foreach (var help in helpWithRegFunction)
                {
                    int index = helpWithRegFunction.IndexOf(help);
                    //如果我的slave id 变更了，我该如何得治
                    await SerialPortConnectionViewModel.
                        iAQBHController.AQBHSendData(theslaveaddr, help.regaddr, help.data);
                    //搞一个进度条转圈
                    if (help.data.Length > 49)
                    {
                        await Task.Delay(100);
                    }
                    await ChangeTheProcess(index, helpWithRegFunction.Count());
                }
                await ChangeTheProcess(1, 1);
            }
            catch (Exception ex){
                var uiMessageBox = new Wpf.Ui.Controls.MessageBox
                {
                    Title = "String Format Error",
                    Content =
                    SetLanguage(globellanguage, "EmptyTroubleMessage")
                };
                var result = await uiMessageBox.ShowDialogAsync();
                await TakeStartOrEnd(false);
                await ChangeTheProcess(1, 1);
                return;
            }
        }
        else if (ServerRegistersSetStatus)
        {
            try
            {
                List<HelpWithRegFunction> helpWithRegFunction = new();
                var ct = (_userNeedShowControl as ServerRegistersView);
                var regsview = (ct!.DataContext as ServerRegistersViewModel);
                pTAConfigModel!.OCPP服务器URL = regsview!.OCPPServer;
                pTAConfigModel!.HTTP身份校验使能 = regsview!.HTTPChecked;
                pTAConfigModel!.HTTP身份校验用户名 = regsview!.HttpUserName;
                pTAConfigModel!.HTTP身份校验密码 = regsview!.HttpUserPassword;
                pTAConfigModel!.ChargePointModel_OCPP = regsview!.ChangePointModel;
                pTAConfigModel!.ChargePointVendor = regsview!.ChargePointVendor;
                pTAConfigModel!.QR_Code_1 = regsview!.QR_Code_1;
                pTAConfigModel!.QR_Code_2 = regsview!.QR_Code_2;
                pTAConfigModel!.QR_Code_3 = regsview!.QR_Code_3;
                pTAConfigModel!.服务器CA证书文件名 = regsview!.AddressText;

                pTAConfigModel!.OCPP服务器URL = 128 > pTAConfigModel!.OCPP服务器URL.Length ? pTAConfigModel!.OCPP服务器URL.PadRight(128, '\0') : pTAConfigModel!.OCPP服务器URL;
                pTAConfigModel!.HTTP身份校验用户名 = 25 > pTAConfigModel!.HTTP身份校验用户名.Length ? pTAConfigModel!.HTTP身份校验用户名.PadRight(25, '\0') : pTAConfigModel!.HTTP身份校验用户名;
                pTAConfigModel!.HTTP身份校验密码 = 25 > pTAConfigModel!.HTTP身份校验密码.Length ? pTAConfigModel!.HTTP身份校验密码.PadRight(25, '\0') : pTAConfigModel!.HTTP身份校验密码;
                pTAConfigModel!.ChargePointModel_OCPP = 25 > pTAConfigModel!.ChargePointModel_OCPP.Length ? pTAConfigModel!.ChargePointModel_OCPP.PadRight(25, '\0') : pTAConfigModel!.ChargePointModel_OCPP;
                pTAConfigModel!.ChargePointVendor = 10 > pTAConfigModel!.ChargePointVendor.Length ? pTAConfigModel!.ChargePointVendor.PadRight(10, '\0') : pTAConfigModel!.ChargePointVendor;

                pTAConfigModel!.QR_Code_1 = 50 > pTAConfigModel!.QR_Code_1.Length ? pTAConfigModel!.QR_Code_1.PadRight(50, '\0') : pTAConfigModel!.QR_Code_1;
                pTAConfigModel!.QR_Code_2 = 50 > pTAConfigModel!.QR_Code_2.Length ? pTAConfigModel!.QR_Code_2.PadRight(50, '\0') : pTAConfigModel!.QR_Code_2;
                pTAConfigModel!.QR_Code_3 = 50 > pTAConfigModel!.QR_Code_3.Length ? pTAConfigModel!.QR_Code_3.PadRight(50, '\0') : pTAConfigModel!.QR_Code_3;
                pTAConfigModel!.服务器CA证书文件名 = 50 > pTAConfigModel!.服务器CA证书文件名.Length ? pTAConfigModel!.服务器CA证书文件名.PadRight(50, '\0') : pTAConfigModel!.服务器CA证书文件名;

                pTAConfigModel!.服务器证书数组 = PEMModel.PEMModelSet(regsview!.AddressText);


                if (!string.IsNullOrEmpty(pTAConfigModel!.OCPP服务器URL))
                {
                    var length = pTAConfigModel!.OCPP服务器URL.Length;
                    helpWithRegFunction.Add(new HelpWithRegFunction
                    {
                        data = StrignToUShort(pTAConfigModel!.OCPP服务器URL.Substring(0, 123), 123, true),
                        regaddr = (ushort)mB_ServerRegisiters.OCPP服务器URL
                    });
                    helpWithRegFunction.Add(new HelpWithRegFunction
                    {
                        data = StrignToUShort(pTAConfigModel!.OCPP服务器URL.Substring(123), 5, true),
                        regaddr = (ushort)mB_ServerRegisiters.OCPP服务器URL + 123
                    });
                }
                #region 因为 ARM 端的写入分界有些拥挤故而用此不合适的拆解
                //helpWithRegFunction.LastOrDefault()!.data = helpWithRegFunction.LastOrDefault()!.data.Concat([(ushort)(pTAConfigModel!.HTTP身份校验使能.Value ? 1 : 0)]).ToArray();
                //helpWithRegFunction.LastOrDefault()!.data = helpWithRegFunction.LastOrDefault()!.data.Concat(StrignToUShort(pTAConfigModel!.HTTP身份校验用户名, 25, true)).ToArray();
                //helpWithRegFunction.LastOrDefault()!.data = helpWithRegFunction.LastOrDefault()!.data.Concat(StrignToUShort(pTAConfigModel!.HTTP身份校验密码, 25, true)).ToArray();
                //helpWithRegFunction.LastOrDefault()!.data = helpWithRegFunction.LastOrDefault()!.data.Concat(StrignToUShort(pTAConfigModel!.ChargePointModel_OCPP, 25, true)).ToArray();
                //helpWithRegFunction.LastOrDefault()!.data = helpWithRegFunction.LastOrDefault()!.data.Concat(StrignToUShort(pTAConfigModel!.ChargePointVendor, 10, true)).ToArray();
                //helpWithRegFunction.LastOrDefault()!.data = helpWithRegFunction.LastOrDefault()!.data.Concat(StrignToUShort(pTAConfigModel!.QR_Code_1.Substring(0, 32), 32, true)).ToArray();

                //helpWithRegFunction.Add(new HelpWithRegFunction
                //{
                //    data = StrignToUShort(pTAConfigModel!.QR_Code_1.Substring(32), 18, true),
                //    regaddr = (ushort)mB_ServerRegisiters.写入专用寄存器3
                //});
                //helpWithRegFunction.LastOrDefault()!.data = helpWithRegFunction.LastOrDefault()!.data.Concat(StrignToUShort(pTAConfigModel!.QR_Code_2, 50, false)).ToArray();
                //helpWithRegFunction.LastOrDefault()!.data = helpWithRegFunction.LastOrDefault()!.data.Concat(StrignToUShort(pTAConfigModel!.QR_Code_3, 50, false)).ToArray();
                #endregion
                #region 因为不支持点对点的polling 而设立的垃圾箱
                helpWithRegFunction.Add(new HelpWithRegFunction
                {
                    data = [(ushort)(pTAConfigModel!.HTTP身份校验使能.Value ? 1 : 0)],
                    regaddr = (ushort)mB_ServerRegisiters.HTTP身份校验使能
                });
                if (!string.IsNullOrEmpty(pTAConfigModel!.HTTP身份校验用户名))
                {
                    helpWithRegFunction.Add(new HelpWithRegFunction
                    {
                        data = StrignToUShort(pTAConfigModel!.HTTP身份校验用户名, 25, true),
                        regaddr = (ushort)mB_ServerRegisiters.HTTP身份校验用户名
                    });
                }
                if (!string.IsNullOrEmpty(pTAConfigModel!.HTTP身份校验密码))
                {
                    helpWithRegFunction.Add(new HelpWithRegFunction
                    {
                        data = StrignToUShort(pTAConfigModel!.HTTP身份校验密码, 25, true),
                        regaddr = (ushort)mB_ServerRegisiters.HTTP身份校验密码
                    });
                }
                if (!string.IsNullOrEmpty(pTAConfigModel!.ChargePointModel_OCPP))
                {
                    helpWithRegFunction.Add(new HelpWithRegFunction
                    {
                        data = StrignToUShort(pTAConfigModel!.ChargePointModel_OCPP, 25, true),
                        regaddr = (ushort)mB_ServerRegisiters.ChargePointModel_OCPP
                    });
                }
                if (!string.IsNullOrEmpty(pTAConfigModel!.ChargePointVendor))
                {
                    helpWithRegFunction.Add(new HelpWithRegFunction
                    {
                        data = StrignToUShort(pTAConfigModel!.ChargePointVendor, 10, true),
                        regaddr = (ushort)mB_ServerRegisiters.ChargePointVendor
                    });
                }
                if (!string.IsNullOrEmpty(pTAConfigModel!.QR_Code_1))
                {
                    helpWithRegFunction.Add(new HelpWithRegFunction
                    {
                        data = StrignToUShort(pTAConfigModel!.QR_Code_1, 50, false).Concat(StrignToUShort(pTAConfigModel!.QR_Code_2, 50, false)).ToArray(),
                        regaddr = (ushort)mB_ServerRegisiters.QR_Code_1
                    });
                }
                //if (!string.IsNullOrEmpty(pTAConfigModel!.QR_Code_2))
                //{
                //    helpWithRegFunction.Add(new HelpWithRegFunction
                //    {
                //        data = StrignToUShort(pTAConfigModel!.QR_Code_2, 50, false),
                //        regaddr = (ushort)mB_ServerRegisiters.QR_Code_2
                //    });
                //}
                if (!string.IsNullOrEmpty(pTAConfigModel!.QR_Code_3))
                {
                    helpWithRegFunction.Add(new HelpWithRegFunction
                    {
                        data = StrignToUShort(pTAConfigModel!.QR_Code_3, 50, false).Concat(StrignToUShort(pTAConfigModel!.服务器CA证书文件名, 50, false)).ToArray(),
                        regaddr = (ushort)mB_ServerRegisiters.QR_Code_3
                    });
                }
                #endregion
                if (!string.IsNullOrEmpty(pTAConfigModel!.服务器CA证书文件名))
                {
                    helpWithRegFunction.Add(new HelpWithRegFunction
                    {
                        data = StrignToUShort(pTAConfigModel!.服务器CA证书文件名, 50, false),
                        regaddr = (ushort)mB_ServerRegisiters.服务器CA证书文件名
                    });
                }

                foreach (var help in helpWithRegFunction)
                {
                    int index = helpWithRegFunction.IndexOf(help);
                    //如果我的slave id 变更了，我该如何得治
                    await SerialPortConnectionViewModel.
                        iAQBHController.AQBHSendData((theslaveaddr), help.regaddr, help.data);
                    //搞一个进度条转圈
                    await ChangeTheProcess(index, helpWithRegFunction.Count());
                }
                await ChangeTheProcess(1, 1);
            }
            catch (Exception ex){
                var uiMessageBox = new Wpf.Ui.Controls.MessageBox
                {
                    Title = "String Format Error",
                    Content =
                    SetLanguage(globellanguage, "EmptyTroubleMessage")
                };
                var result = await uiMessageBox.ShowDialogAsync();
                await TakeStartOrEnd(false);
                await ChangeTheProcess(1, 1);
                return;
            }
        }
        else if (FTRegistersSetStatus)
        {
            try
            {
                List<HelpWithRegFunction> helpWithRegFunction = new();
                var ct = (_userNeedShowControl as FTRegistersView);
                var regsview = (ct!.DataContext as FTRegistersViewModel);
                #region 一坨
                pTAConfigModel!.Connecotr_Type1 = regsview!.FTRegistersList[0];
                pTAConfigModel!.Connecotr_Type2 = regsview!.FTRegistersList[1];
                pTAConfigModel!.Connecotr_Type3 = regsview!.FTRegistersList[2];

                pTAConfigModel!.直流输出最大电压能力 = regsview!.MaxDCVoltage;
                pTAConfigModel!.直流输出最小电压能力 = regsview!.MinDCVoltage;
                pTAConfigModel!.直流输出最大电流能力 = regsview!.MaxDCCurrent;
                pTAConfigModel!.直流输出最小电流能力 = regsview!.MinDCCurrent;
                pTAConfigModel!.交流输入额定相电压_L_N = regsview!.ACLN;
                pTAConfigModel!.是否启用网络安全策略 = regsview!.NetWorkSecurity;
                pTAConfigModel!.硬件是否具备水浸传感器 = regsview!.WaterImmersion;
                pTAConfigModel!.硬件是否具备倾斜传感器 = regsview!.Dumping;
                pTAConfigModel!.硬件是否具备烟雾传感器 = regsview!.Smog;
                pTAConfigModel!.硬件是否具备湿度传感器 = regsview!.HumiditySensor;
                pTAConfigModel!.硬件是否具备POS机 = regsview!.POS;
                pTAConfigModel!.硬件是否具备加热器 = regsview!.Heater;
                pTAConfigModel!.风扇数量 = regsview!.NumberFans;

                pTAConfigModel!.风扇反馈类型1 = regsview!.WithoutChecked;
                pTAConfigModel!.风扇反馈类型2 = regsview!.PWMChecked;
                pTAConfigModel!.风扇反馈类型3 = regsview!.RDChecked;
                pTAConfigModel!.功率分配模式 = regsview!.SignaleChecked;
                pTAConfigModel!.功率分配模式2 = regsview!.DuoChecked;
                pTAConfigModel!.串联接触器分割的模块数量1 = regsview!.SignalMode1;
                pTAConfigModel!.串联接触器分割的模块数量2 = regsview!.SignalMode2;
                pTAConfigModel!.并联接触器分割的模块数量1 = regsview!.DuoMode1;
                pTAConfigModel!.并联接触器分割的模块数量2 = regsview!.DuoMode2;
                pTAConfigModel!.并联接触器分割的模块数量3 = regsview!.DuoMode3;
                pTAConfigModel!.并联接触器分割的模块数量4 = regsview!.DuoMode4;

                pTAConfigModel!.直流输出最大电压能力2 = regsview!.MaxDCVoltageGun2;
                pTAConfigModel!.直流输出最小电压能力2 = regsview!.MinDCVoltageGun2;
                pTAConfigModel!.直流输出最大电流能力2 = regsview!.MaxDCCurrentGun2;
                pTAConfigModel!.直流输出最小电流能力2 = regsview!.MinDCCurrentGun2;
                pTAConfigModel!.触摸屏灵敏度 = regsview!.TouchScreenSensitivity;
                pTAConfigModel!.充电桩出厂序列号_需要与铭牌一致 = regsview!.SerialNumber;
                pTAConfigModel!.雷达传感器 = regsview!.RadarSensor;
                pTAConfigModel!.液冷泵 = regsview!.LiquidCoolingPump;
                pTAConfigModel!.温度传感启用 = regsview!.TempSensor;
                pTAConfigModel!.单个UU模块最大功率1 = regsview!.SignaleWind_1;
                pTAConfigModel!.单个UU模块最大功率2 = regsview!.SignaleWind_2;
                pTAConfigModel!.单个UU模块最大功率3 = regsview!.SignaleWind_3;
                pTAConfigModel!.GBT_24V辅助电源 = regsview!.GBTHelpVoltage;
                pTAConfigModel!.PTB_电表 = regsview!.PTBElc;


                pTAConfigModel!.充电桩出厂序列号_需要与铭牌一致 = 10 > pTAConfigModel!.充电桩出厂序列号_需要与铭牌一致.Length ? pTAConfigModel!.充电桩出厂序列号_需要与铭牌一致.PadRight(10, '\0') : pTAConfigModel!.充电桩出厂序列号_需要与铭牌一致;
                #endregion

                helpWithRegFunction.Add(new HelpWithRegFunction
                {
                    data = [(ushort)pTAConfigModel!.Connecotr_Type1.ConnectorIndex],
                    regaddr = (ushort)mB_FTRegisiters.Connecotr_Type1Addr
                });
                helpWithRegFunction.Add(new HelpWithRegFunction
                {
                    data = [(ushort)pTAConfigModel!.Connecotr_Type2.ConnectorIndex],
                    regaddr = (ushort)mB_FTRegisiters.Connecotr_Type2Addr
                });
                helpWithRegFunction.Add(new HelpWithRegFunction
                {
                    data = [(ushort)pTAConfigModel!.Connecotr_Type3.ConnectorIndex],
                    regaddr = (ushort)mB_FTRegisiters.Connecotr_Type3Addr
                });
                if (!string.IsNullOrEmpty(pTAConfigModel!.Connecotr_Type1.SignalShot))
                {
                    helpWithRegFunction.Add(new HelpWithRegFunction
                    {
                        data = [ushort.Parse(pTAConfigModel!.Connecotr_Type1.SignalShot)],
                        regaddr = (ushort)mB_FTRegisiters.单枪功率_电流限制_硬件限制1地址
                    });
                }
                if (!string.IsNullOrEmpty(pTAConfigModel!.Connecotr_Type2.SignalShot))
                {
                    helpWithRegFunction.Add(new HelpWithRegFunction
                    {
                        data = [ushort.Parse(pTAConfigModel!.Connecotr_Type2.SignalShot)],
                        regaddr = (ushort)mB_FTRegisiters.单枪功率_电流限制_硬件限制2地址
                    });
                }
                if (!string.IsNullOrEmpty(pTAConfigModel!.Connecotr_Type3.SignalShot))
                {
                    helpWithRegFunction.Add(new HelpWithRegFunction
                    {
                        data = [ushort.Parse(pTAConfigModel!.Connecotr_Type3.SignalShot)],
                        regaddr = (ushort)mB_FTRegisiters.单枪功率_电流限制_硬件限制3地址
                    });
                }

                if (!string.IsNullOrEmpty(pTAConfigModel!.直流输出最大电压能力))
                {
                    helpWithRegFunction.Add(new HelpWithRegFunction
                    {
                        data = [ushort.Parse(pTAConfigModel!.直流输出最大电压能力)],
                        regaddr = (ushort)mB_FTRegisiters.直流输出最大电压能力地址
                    });
                }
                if (!string.IsNullOrEmpty(pTAConfigModel!.直流输出最小电压能力))
                {
                    helpWithRegFunction.Add(new HelpWithRegFunction
                    {
                        data = [ushort.Parse(pTAConfigModel!.直流输出最小电压能力)],
                        regaddr = (ushort)mB_FTRegisiters.直流输出最小电压能力地址
                    });
                }
                if (!string.IsNullOrEmpty(pTAConfigModel!.直流输出最大电流能力))
                {
                    helpWithRegFunction.Add(new HelpWithRegFunction
                    {
                        data = [ushort.Parse(pTAConfigModel!.直流输出最大电流能力)],
                        regaddr = (ushort)mB_FTRegisiters.直流输出最大电流能力地址
                    });
                }
                if (!string.IsNullOrEmpty(pTAConfigModel!.直流输出最小电流能力))
                {
                    helpWithRegFunction.Add(new HelpWithRegFunction
                    {
                        data = [ushort.Parse(pTAConfigModel!.直流输出最小电流能力)],
                        regaddr = (ushort)mB_FTRegisiters.直流输出最小电流能力地址
                    });
                }
                if (!string.IsNullOrEmpty(pTAConfigModel!.交流输入额定相电压_L_N))
                {
                    helpWithRegFunction.Add(new HelpWithRegFunction
                    {
                        data = [ushort.Parse(pTAConfigModel!.交流输入额定相电压_L_N)],
                        regaddr = (ushort)mB_FTRegisiters.交流输入额定相电压_L_N地址
                    });
                }
                helpWithRegFunction.Add(new HelpWithRegFunction
                {
                    data = [(ushort)(pTAConfigModel!.是否启用网络安全策略.Value ? 1 : 0)],
                    regaddr = (ushort)mB_FTRegisiters.是否启用网络安全策略地址
                });
                helpWithRegFunction.Add(new HelpWithRegFunction
                {
                    data = [(ushort)(pTAConfigModel!.硬件是否具备水浸传感器.Value ? 1 : 0)],
                    regaddr = (ushort)mB_FTRegisiters.硬件是否具备水浸传感器地址
                });
                helpWithRegFunction.Add(new HelpWithRegFunction
                {
                    data = [(ushort)(pTAConfigModel!.硬件是否具备倾斜传感器.Value ? 1 : 0)],
                    regaddr = (ushort)mB_FTRegisiters.硬件是否具备倾斜传感器地址
                });
                helpWithRegFunction.Add(new HelpWithRegFunction
                {
                    data = [(ushort)(pTAConfigModel!.硬件是否具备烟雾传感器.Value ? 1 : 0)],
                    regaddr = (ushort)mB_FTRegisiters.硬件是否具备烟雾传感器地址
                });
                helpWithRegFunction.Add(new HelpWithRegFunction
                {
                    data = [(ushort)(pTAConfigModel!.硬件是否具备湿度传感器.Value ? 1 : 0)],
                    regaddr = (ushort)mB_FTRegisiters.硬件是否具备湿度传感器地址
                });
                helpWithRegFunction.Add(new HelpWithRegFunction
                {
                    data = [(ushort)(pTAConfigModel!.硬件是否具备POS机.Value ? 1 : 0)],
                    regaddr = (ushort)mB_FTRegisiters.硬件是否具备POS机地址
                });
                helpWithRegFunction.Add(new HelpWithRegFunction
                {
                    data = [(ushort)(pTAConfigModel!.硬件是否具备加热器.Value ? 1 : 0)],
                    regaddr = (ushort)mB_FTRegisiters.硬件是否具备加热器地址
                });
                helpWithRegFunction.Add(new HelpWithRegFunction
                {
                    data = [ushort.Parse(pTAConfigModel!.风扇数量)],
                    regaddr = (ushort)mB_FTRegisiters.风扇数量地址
                });

                ushort feedbacktype = 0;
                if (pTAConfigModel!.风扇反馈类型1.Value)
                    feedbacktype = 0;
                else if (pTAConfigModel!.风扇反馈类型2.Value)
                    feedbacktype = 1;
                else if (pTAConfigModel!.风扇反馈类型3.Value)
                    feedbacktype = 2;
                helpWithRegFunction.Add(new HelpWithRegFunction
                {
                    data = [feedbacktype],
                    regaddr = (ushort)mB_FTRegisiters.风扇反馈类型地址
                });
                helpWithRegFunction.Add(new HelpWithRegFunction
                {
                    data = [(ushort)(pTAConfigModel!.功率分配模式.Value ? 0 : 1)],
                    regaddr = (ushort)mB_FTRegisiters.功率分配模式地址
                });
                if (pTAConfigModel!.功率分配模式.Value)
                {
                    if (!string.IsNullOrEmpty(pTAConfigModel!.串联接触器分割的模块数量1)
                        && !string.IsNullOrEmpty(pTAConfigModel!.串联接触器分割的模块数量2))
                    {
                        helpWithRegFunction.Add(new HelpWithRegFunction
                        {
                            data = [ushort.Parse(pTAConfigModel!.串联接触器分割的模块数量1),
                            ushort.Parse(pTAConfigModel!.串联接触器分割的模块数量2)],
                            regaddr = (ushort)mB_FTRegisiters.并联接触器分割的模块数量地址
                        });
                    }
                    else
                    {
                        var uiMessageBox = new Wpf.Ui.Controls.MessageBox
                        {
                            Title = "The error of model number can not be empty.",
                            Content =
                                    "Write Error. ",
                        };
                        var result = await uiMessageBox.ShowDialogAsync();
                        await TakeStartOrEnd(false);
                        await ChangeTheProcess(1, 1);
                        return;
                    }
                }
                else
                {
                    if (!string.IsNullOrEmpty(pTAConfigModel!.并联接触器分割的模块数量1)
                        && !string.IsNullOrEmpty(pTAConfigModel!.并联接触器分割的模块数量2)
                        && !string.IsNullOrEmpty(pTAConfigModel!.并联接触器分割的模块数量3)
                        && !string.IsNullOrEmpty(pTAConfigModel!.并联接触器分割的模块数量4)
                        )
                    {
                        helpWithRegFunction.Add(new HelpWithRegFunction
                        {
                            data = [ushort.Parse(pTAConfigModel!.并联接触器分割的模块数量1),
                            ushort.Parse(pTAConfigModel!.并联接触器分割的模块数量2),
                            ushort.Parse(pTAConfigModel!.并联接触器分割的模块数量3),
                            ushort.Parse(pTAConfigModel!.并联接触器分割的模块数量4)
                                ],
                            regaddr = (ushort)mB_FTRegisiters.并联接触器分割的模块数量地址
                        });
                    }
                    else
                    {
                        var uiMessageBox = new Wpf.Ui.Controls.MessageBox
                        {
                            Title = "The error of model number can not be empty.",
                            Content =
                                "   Write Error. ",
                        };
                        var result = await uiMessageBox.ShowDialogAsync();
                        await ChangeTheProcess(1, 1);
                        return;
                    }
                }
                if (!string.IsNullOrEmpty(pTAConfigModel!.直流输出最大电压能力2))
                {
                    helpWithRegFunction.Add(new HelpWithRegFunction
                    {
                        data = [ushort.Parse(pTAConfigModel!.直流输出最大电压能力2)],
                        regaddr = (ushort)mB_FTRegisiters.直流输出最大电压能力2地址
                    });
                }
                if (!string.IsNullOrEmpty(pTAConfigModel!.直流输出最小电压能力2))
                {
                    helpWithRegFunction.Add(new HelpWithRegFunction
                    {
                        data = [ushort.Parse(pTAConfigModel!.直流输出最小电压能力2)],
                        regaddr = (ushort)mB_FTRegisiters.直流输出最小电压能力2地址
                    });
                }
                if (!string.IsNullOrEmpty(pTAConfigModel!.直流输出最大电流能力2))
                {
                    helpWithRegFunction.Add(new HelpWithRegFunction
                    {
                        data = [ushort.Parse(pTAConfigModel!.直流输出最大电流能力2)],
                        regaddr = (ushort)mB_FTRegisiters.直流输出最大电流能力2地址
                    });
                }
                if (!string.IsNullOrEmpty(pTAConfigModel!.直流输出最小电流能力2))
                {
                    helpWithRegFunction.Add(new HelpWithRegFunction
                    {
                        data = [ushort.Parse(pTAConfigModel!.直流输出最小电流能力2)],
                        regaddr = (ushort)mB_FTRegisiters.直流输出最小电流能力2地址
                    });
                }
                helpWithRegFunction.Add(new HelpWithRegFunction
                {
                    data = [(ushort)pTAConfigModel!.触摸屏灵敏度],
                    regaddr = (ushort)mB_FTRegisiters.触摸屏灵敏度地址
                });
                if (!string.IsNullOrEmpty(pTAConfigModel!.充电桩出厂序列号_需要与铭牌一致))
                {
                    helpWithRegFunction.Add(new HelpWithRegFunction
                    {
                        data = StrignToUShort(pTAConfigModel!.充电桩出厂序列号_需要与铭牌一致, 10, false),
                        regaddr = (ushort)mB_FTRegisiters.充电桩出厂序列号_需要与铭牌一致地址
                    });
                }
                helpWithRegFunction.Add(new HelpWithRegFunction
                {
                    data = [(ushort)(pTAConfigModel!.雷达传感器.Value ? 1 : 0)],
                    regaddr = (ushort)mB_FTRegisiters.雷达传感器地址
                });
                helpWithRegFunction.Add(new HelpWithRegFunction
                {
                    data = [(ushort)(pTAConfigModel!.液冷泵.Value ? 1 : 0)],
                    regaddr = (ushort)mB_FTRegisiters.液冷泵地址
                });
                helpWithRegFunction.Add(new HelpWithRegFunction
                {
                    data = [(ushort)(pTAConfigModel!.温度传感启用.Value ? 1 : 0)],
                    regaddr = (ushort)mB_FTRegisiters.温度传感启用地址
                });
                ushort uu = 0;
                if (pTAConfigModel!.单个UU模块最大功率1.Value)
                    uu = 0;
                else if (pTAConfigModel!.单个UU模块最大功率2.Value)
                    uu = 1;
                else if (pTAConfigModel!.单个UU模块最大功率3.Value)
                    uu = 2;
                helpWithRegFunction.Add(new HelpWithRegFunction
                {
                    data = [uu],
                    regaddr = (ushort)mB_FTRegisiters.单个UU模块最大功率地址
                });
                helpWithRegFunction.Add(new HelpWithRegFunction
                {
                    data = [(ushort)(pTAConfigModel!.GBT_24V辅助电源.Value ? 1 : 0)],
                    regaddr = (ushort)mB_FTRegisiters.GBT_24V辅助电源地址
                });
                helpWithRegFunction.Add(new HelpWithRegFunction
                {
                    data = [(ushort)(pTAConfigModel!.PTB_电表.Value ? 1 : 0)],
                    regaddr = (ushort)mB_FTRegisiters.PTB_电表地址
                });
                foreach (var help in helpWithRegFunction)
                {
                    int index = helpWithRegFunction.IndexOf(help);
                    //如果我的slave id 变更了，我该如何得治
                    await SerialPortConnectionViewModel.
                        iAQBHController.AQBHSendData(theslaveaddr, help.regaddr, help.data);
                    //搞一个进度条转圈
                    if (help.data.Length > 49)
                        await Task.Delay(20);
                    await ChangeTheProcess(index, helpWithRegFunction.Count());
                }
                await ChangeTheProcess(1, 1);
            }
            catch(Exception ex)
            {
                var uiMessageBox = new Wpf.Ui.Controls.MessageBox
                {
                    Title = "String Format Error",
                    Content =
                    SetLanguage(globellanguage, "EmptyTroubleMessage")
                };
                var result = await uiMessageBox.ShowDialogAsync();
                await TakeStartOrEnd(false);
                await ChangeTheProcess(1, 1);
                return;
            }
        }
    }
    #endregion
    private ushort[] SplitAddr(string ip)
    {
        var _ = ip.Split(".");
        if (_.Length < 4)
        {
            return [0,0,0,0];
        }
        return _.Select(x => ushort.Parse(x)).ToArray();
    }

    public ICommand ReStartCommand =>
    new RelayCommand(async () => await ReStartCommandFunc());

    private async Task ReStartCommandFunc()
    {
        ushort[] data = [0x01];
        await SerialPortConnectionViewModel.
            iAQBHController.AQBHSendData(theslaveaddr, 1280, data);

        var uiMessageBox = new Wpf.Ui.Controls.MessageBox
        {
            Title = "Reg Message.",
            Content =
            "复位成功. ",
        };
        var result = await uiMessageBox.ShowDialogAsync();

    }

    public static string globellanguage { get; set; } = string.Empty;
    public void GlobleLanguageChangeFunc()
    {
        Restart = SetLanguage(globellanguage, "Restart");
        OneClickConfigText = SetLanguage(globellanguage, "One Click Configuration");
        User_Regisiter = SetLanguage(globellanguage, "User Regisiter");
        Network_Regisiter = SetLanguage(globellanguage, "Network Regisiter");
        Server_Regisiter = SetLanguage(globellanguage, "Server Regisiter");
        FT_Regisiter = SetLanguage(globellanguage, "FT Regisiter");

        SerialPortConnectionUserControl = new SerialPortConnectionView();
        CommonRegistersManagementUserControl = new CommonRegistersManagement();
        //NetworkRegisterCommandFunc();

    }
    public MainWindowViewModel()
    {
        Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
        globellanguage = CultureInfo.CurrentUICulture.Name;
        #region 根据序列化确定是否是admin

        string _appStartupPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)!;

        string filePath = new(Path.Combine
                        (_appStartupPath!, "Lisence"));
        string machineCode = LicenseGenerator.GenerateMachineCode();

        if (!Directory.Exists(filePath))
        {
            Directory.CreateDirectory(filePath);
        }
        string file = new(Path.Combine
                        (filePath!, "PublicKey.json"));

        if (!File.Exists(file))
        {
            File.Create(file).Close();
        }
        string json = File.ReadAllText(file);
        if (!string.IsNullOrEmpty(json))
        {
            var _ = JsonConvert.DeserializeObject(json)!;
            byte[] key = Encoding.UTF8.GetBytes("1536518558527742");  // 16字节密钥
            byte[] iv = Encoding.UTF8.GetBytes("1396874257847166");   // 16字节IV
            var deb = ActivationKeyGenerator.AESDecrypt(Convert.FromBase64String(_.ToString()!), key, iv);
            if (string.Equals(deb, machineCode))
                FTVisibility = Visibility.Visible;
            else
                FTVisibility = Visibility.Hidden;
        }
        else
            FTVisibility = Visibility.Hidden;
        #endregion
        EnglishCheck = true;
        string savepath = new(Path.Combine
                (AppContext.BaseDirectory!, "Assets", "Country"));
        var filr = Directory.GetFiles(savepath);
        EnglishImage = filr.Where(x => x.Contains("English")).FirstOrDefault()!.ToString();
        ChinaImage = filr.Where(x => x.Contains("简体中文")).FirstOrDefault()!.ToString();
        //FTVisibility = Visibility.Visible;
        UserRegistersCommandFunc();
        Task.Run(async () =>
        {
            await ProcessRun();
        });
        //Task.Run(async () =>
        //{
        //    await ConnectionBinding();
        //});
    }
    private static ResourceManager _resourceManager =
    new ResourceManager("充电桩上位机.Directorys.GrobleDirectory",
                        Assembly.GetExecutingAssembly());
    public static string SetLanguage(string cultureName, string key)
    {
        CultureInfo.CurrentUICulture = new CultureInfo(cultureName);
        return _resourceManager.GetString(key, CultureInfo.CurrentUICulture)!;
    }
    private ushort[] ConvertUintToUShortArray(uint value)
    {
        ushort[] result = new ushort[2];
        try
        {
            // 低16位
            result[1] = (ushort)(value & 0xFFFF);

            // 高16位
            result[0] = (ushort)((value >> 16) & 0xFFFF);
        }
        catch (IndexOutOfRangeException ex)
        {
            Console.WriteLine("An error occurred: " + ex.Message);
            // 查看堆栈跟踪信息
            Console.WriteLine(ex.StackTrace);
        }

        return result;
    }
    #region Globle 全球化语言
    [Category("硬件重置")]
    private string _restart = string.Empty;
    public string Restart
    {
        get => _restart;
        set => SetProperty(ref _restart, value);
    }
    [Category("配置控件文字")]
    private string _oneClickConfigText = string.Empty;
    public string OneClickConfigText
    {
        get => _oneClickConfigText;
        set => SetProperty(ref _oneClickConfigText, value);
    }
    [Category("用户寄存器")]
    private string _user_Regisiter = string.Empty;
    public string User_Regisiter
    {
        get => _user_Regisiter;
        set => SetProperty(ref _user_Regisiter, value);
    }
    [Category("网络寄存器")]
    private string _network_Regisiter = string.Empty;
    public string Network_Regisiter
    {
        get => _network_Regisiter;
        set => SetProperty(ref _network_Regisiter, value);
    }    
    [Category("服务寄存器")]
    private string _server_Regisiter = string.Empty;
    public string Server_Regisiter
    {
        get => _server_Regisiter;
        set => SetProperty(ref _server_Regisiter, value);
    }
    [Category("FT 硬件寄存器")]
    private string _fT_Regisiter = string.Empty;
    public string FT_Regisiter
    {
        get => _fT_Regisiter;
        set => SetProperty(ref _fT_Regisiter, value);
    }

    #endregion
    #region 断网后防止读写出现异常
    private bool _connectedIsCheck = false;
    public bool ConnectedIsCheck
    {
        get => _connectedIsCheck;
        set => SetProperty(ref _connectedIsCheck, value);
    }
    //public async Task ConnectionBinding()
    //{
    //    while(true)
    //    {
    //        try
    //        {
    //            var ct = SerialPortConnectionUserControl as SerialPortConnectionView;
    //            if (ct != null)
    //            {
    //                await Task.Delay(1000);
    //                var machine = (ct!.DataContext as SerialPortConnectionViewModel);
    //                if (machine!.JoinCommand)
    //                {
    //                    var regpu = await SerialPortConnectionViewModel.iAQBHController.AQReadData(theslaveaddr, 1, 10);
    //                    var result = UShortToString(regpu, 0, 10, 10, false);

    //                }
    //            }
    //        }
    //        catch
    //        {

    //            var ct = SerialPortConnectionUserControl as SerialPortConnectionView;
    //            var machine = (ct!.DataContext as SerialPortConnectionViewModel);
    //            machine!.JoinCommand = false;

    //        }
    //        await Task.Delay(1000);
    //    }
    //}
    #endregion
}
